0
0
Ruby on Railsframework~8 mins

Background email delivery in Ruby on Rails - Performance & Optimization

Choose your learning style9 modes available
Performance: Background email delivery
HIGH IMPACT
This affects page load speed and user interaction responsiveness by offloading email sending from the main request cycle.
Sending emails after user actions without blocking the UI
Ruby on Rails
def create
  UserMailer.welcome_email(@user).deliver_later
  redirect_to root_path
end
Email is queued and sent asynchronously, freeing the web request to complete immediately.
📈 Performance GainNon-blocking request, improves INP by hundreds of milliseconds
Sending emails after user actions without blocking the UI
Ruby on Rails
def create
  UserMailer.welcome_email(@user).deliver_now
  redirect_to root_path
end
Sending email synchronously blocks the web request until the email is sent, causing slow response times.
📉 Performance CostBlocks rendering for 500ms+ depending on email server response
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Synchronous email sending (deliver_now)N/AN/ABlocks response, delays paint[X] Bad
Asynchronous email sending (deliver_later)N/AN/ANon-blocking, fast paint[OK] Good
Rendering Pipeline
Synchronous email sending blocks the main thread during the request, delaying response and paint. Background delivery moves email sending to a separate job queue, allowing the browser to receive and render the page faster.
Request Handling
Response Time
Interaction Responsiveness
⚠️ BottleneckRequest Handling blocking on email delivery
Core Web Vital Affected
INP
This affects page load speed and user interaction responsiveness by offloading email sending from the main request cycle.
Optimization Tips
1Never send emails synchronously during web requests.
2Use deliver_later with a background job processor like Sidekiq or Delayed Job.
3Monitor background job queues to ensure timely email delivery.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance problem with sending emails synchronously during a web request?
AIt causes layout shifts on the page
BIt increases CSS paint time
CIt blocks the request, delaying page load and interaction
DIt reduces image loading speed
DevTools: Performance
How to check: Record a performance profile while triggering the email sending action. Look for long tasks blocking the main thread during the request.
What to look for: Long blocking tasks or delayed Time to Interactive indicate synchronous email sending.