Queue Architecture
Location:app/config.py:12
Queue Definitions
Queue Configuration
Core Tasks
Job Processing Tasks
Location:app/celery/tasks.py
process-job
- Updates job status to
in progress - Validates service is active
- Checks daily sending limits
- Reads recipient CSV from S3
- Batches rows (default 32) and creates subtasks
- Each batch sent to
shatter-job-rowstask - Marks job as
finished
shatter-job-rows
- Handles SQS message size limits via recursive subdivision
- Routes to appropriate save task based on notification type
- Queue:
JOBS
Notification Saving Tasks
Location:app/celery/tasks.py:275
save-sms
- Decode signed notification data
- Load service and template
- Validate recipient format
- Persist notification to database
- Queue
deliver_smstask toSEND_SMS
- Invalid phone numbers marked as
validation-failed - SQLAlchemy errors trigger retry with exponential backoff
- Max retries: 5, delay: 300s
save-email
- Adds email file attachment links to personalisation
- Handles reply-to address configuration
- Unsubscribe link generation if enabled
save-letter
- Parse postal address from personalisation
- Determine postage (first/second class, international)
- Persist notification
- Queue
get_pdf_for_templated_lettertoCREATE_LETTERS_PDF
Provider Delivery Tasks
Location:app/celery/provider_tasks.py
deliver_sms
SmsClientResponseException→ retry- Max retries exceeded → mark as
technical-failure - First retry: immediate (countdown=0)
- Subsequent retries: 300s delay
- Queue:
RETRYfor all retries
deliver_email
EmailClientNonRetryableException→ immediatetechnical-failure(no retry)AwsSesClientThrottlingSendRateException→ retry with warning- Generic exceptions → retry
deliver_letter
- Validate notification status is
created - Fetch PDF from S3
- Send to DVLA API with callback URL
- Update status to
sending
DvlaThrottlingException→ retry with warningDvlaRetryableException→ retryDvlaDuplicatePrintRequestException→ mark sending (idempotent)- Other exceptions →
technical-failure
Scheduled Tasks
Location:app/config.py:282 (beat_schedule)
High-Frequency Tasks (Every Minute)
Periodic Tasks
Nightly Tasks
Letter Collation
Weekly/Monthly Tasks
Task Design Patterns
Retry Strategy
Error Handling Hierarchy
- Non-retryable → Immediate technical-failure
- Retryable → Exponential backoff
- Max retries → Technical-failure with logging
Idempotency
All tasks check for duplicate processing:Task Signing
Sensitive data encoded with signing module:Performance Optimizations
Batching
- Job rows batched (default 32) before task creation
- Reduces SQS API calls
- Subdivision if message too large
Queue Separation
- Delivery tasks separated by channel (SMS/Email/Letter)
- Prevents head-of-line blocking
- Independent scaling per queue
Prefetch Multiplier
Monitoring
Tasks emit StatsD metrics:Related Files
app/celery/tasks.py- Job and notification tasksapp/celery/provider_tasks.py- Provider delivery tasksapp/celery/scheduled_tasks.py- Scheduled/periodic tasksapp/celery/nightly_tasks.py- Nightly maintenance tasksapp/celery/reporting_tasks.py- Analytics tasksapp/config.py- Queue and schedule configuration