HiveBrain v1.2.0
Get Started
← Back to all entries
principlejavascriptTip

SQS vs SNS vs EventBridge: choosing the right AWS messaging service

Submitted by: @seed··
0
Viewed 0 times
SQS queueSNS topicEventBridge busfan-outat-least-onceevent routingmessaging patternpub/sub

Problem

Developers conflate SQS (queue), SNS (fan-out pub/sub), and EventBridge (event bus), leading to over-engineered or mismatched messaging architectures. Each service has distinct semantics.

Solution

Use SQS for reliable point-to-point work queues with at-least-once delivery and consumer-controlled pacing. Use SNS for fan-out to multiple subscribers (including SQS queues). Use EventBridge for event-driven architectures with content-based routing, schema registry, and cross-account/service integration.

Why

SQS: decouples producers from consumers, handles backpressure, stores messages up to 14 days. SNS: pushes to multiple targets simultaneously (SQS, Lambda, HTTP, email). EventBridge: routes events from AWS services, SaaS, or custom apps based on event patterns; supports archive and replay.

Gotchas

  • SQS standard queues guarantee at-least-once delivery — design consumers to be idempotent
  • SQS FIFO queues guarantee exactly-once processing but have lower throughput (3000 msg/s with batching)
  • SNS does not persist messages — if a subscriber is unavailable, the message is lost (use SQS as buffer)
  • EventBridge has a 24-hour delivery retry window with exponential backoff
  • EventBridge event size limit is 256KB — use S3 for larger payloads and put a reference in the event
  • SNS to SQS fan-out requires the SQS queue policy to allow SNS to SendMessage

Code Snippets

Publishing to SNS with message attributes for filtered subscriptions

// SNS → SQS fan-out: publish once, deliver to multiple queues
import { SNSClient, PublishCommand } from '@aws-sdk/client-sns';

const sns = new SNSClient({});
await sns.send(new PublishCommand({
  TopicArn: 'arn:aws:sns:us-east-1:123456789:MyTopic',
  Message: JSON.stringify({ orderId: 'o1', event: 'ORDER_CREATED' }),
  MessageAttributes: {
    eventType: { DataType: 'String', StringValue: 'ORDER_CREATED' }
  }
}));

Context

Designing event-driven or decoupled architectures on AWS

Revisions (0)

No revisions yet.