Email Queue

Overview

AWS SQS queue for reliable, asynchronous email delivery with retry logic and dead-letter queue for failed messages.

Queue Configuration

Main Email Queue

  • Queue Type: Standard SQS
  • Message Retention: 14 days
  • Visibility Timeout: 5 minutes
  • Receive Wait Time: 20 seconds (long polling)
  • Max Receives: 3 attempts before DLQ

Dead Letter Queue

  • DLQ Retention: 14 days
  • Purpose: Failed email deliveries for investigation
  • Alarm: CloudWatch alarm on DLQ depth

Technical Details

Specifications:

  • Throughput: 10,000 messages/second
  • Message Size: Max 256 KB
  • Batch Processing: Up to 10 messages per receive
  • Encryption: SSE-SQS encryption enabled

Performance:

  • Delivery Latency: < 1 second
  • Processing Time: < 30 seconds per email
  • Success Rate: > 99%

Message Format

{
"email_type": "task_assigned",
"recipient": "user@example.com",
"template_id": "task_assignment",
"data": {
"task_title": "Fix login bug",
"assignee_name": "Sarah Chen",
"task_url": "https://app.taskflow.com/tasks/123"
},
"priority": "normal",
"scheduled_at": "2024-01-15T10:30:00Z"
}

Processing Flow

  1. Enqueue

    Notification Service publishes email message to SQS

  2. Consumer Poll

    Email Service workers poll queue for messages

  3. Render & Send

    Template rendering and email delivery via SendGrid

  4. Success/Retry

    Success: Delete message. Failure: Retry up to 3 times

  5. DLQ

    After 3 failures, move to dead-letter queue for investigation

Monitoring

  • Queue Depth: Alert if > 10,000 messages
  • Age of Oldest Message: Alert if > 5 minutes
  • DLQ Depth: Alert on any messages
  • Consumer Lag: Monitor processing rate

Retry Strategy

  • Attempt 1: Immediate
  • Attempt 2: 1 minute delay
  • Attempt 3: 5 minutes delay
  • After 3: Move to DLQ