Skip to content

AWS SNS/SQS

Amazon SNS (Simple Notification Service) and SQS (Simple Queue Service) provide managed messaging for event sourcing on AWS.


StrengthBenefit
Fully managedNo infrastructure to operate
ServerlessLambda integration
Cost effectivePay per request
High availabilityMulti-AZ by default
Fan-outSNS → multiple SQS queues

ConcernConsideration
AWS lock-inNot portable to other clouds
256 KB limitLarge events need S3 offloading
OrderingFIFO queues required for ordering

[bus]
backend = "sns_sqs"
[bus.sns_sqs]
region = "us-east-1"
topic_prefix = "angzarr"
Terminal window
export AWS_REGION="us-east-1"
export SNS_SQS_TOPIC_PREFIX="angzarr"
export BUS_BACKEND="sns_sqs"
# AWS credentials via standard mechanisms

SNS provides fan-out to SQS queues:

flowchart LR
    TP["SNS Topic: angzarr-events-player"] --> PP[SQS: player-projector-queue]
    TP --> OP1[SQS: output-projector-queue]
    TH["SNS Topic: angzarr-events-hand"] --> HS[SQS: hand-saga-queue]
    TH --> OP2[SQS: output-projector-queue]

  • At-least-once delivery
  • Best-effort ordering
  • Higher throughput
  • Exactly-once processing
  • Strict ordering within message groups
  • 300 TPS limit (3000 with batching)

For event sourcing, FIFO queues with message group ID = aggregate root:

sqs.send_message()
.queue_url(&fifo_queue_url)
.message_body(&event_json)
.message_group_id(&format!("{}#{}", domain, root))
.message_deduplication_id(&event_id)
.send()
.await?;

Events exceeding 256 KB use S3 for payload storage:

1. Store payload in S3
2. Publish reference to SNS/SQS
3. Consumer fetches from S3

This is the “claim check” pattern, handled automatically by OffloadingEventBus.


Configure DLQs for failed messages:

# CloudFormation/Terraform
PlayerProjectorDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: player-projector-dlq
PlayerProjectorQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: player-projector-queue
RedrivePolicy:
deadLetterTargetArn: !GetAtt PlayerProjectorDLQ.Arn
maxReceiveCount: 5

Terminal window
# Create SNS topics
aws sns create-topic --name angzarr-events-player
aws sns create-topic --name angzarr-events-hand
# Create SQS queues
aws sqs create-queue --queue-name player-projector-queue
# Subscribe queue to topic
aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789:angzarr-events-player \
--protocol sqs \
--notification-endpoint arn:aws:sqs:us-east-1:123456789:player-projector-queue

values.yaml
bus:
backend: sns_sqs
sns_sqs:
enabled: true
region: us-east-1
topicPrefix: angzarr
# IAM role-based auth recommended

  • AWS native — Already on AWS
  • Lambda integration — Serverless event handlers
  • Cost sensitive — Pay-per-use model
  • Managed — No operational overhead

  • Pub/Sub — GCP equivalent
  • AMQP — Self-managed alternative