All sheets / Cloud & Infra
AWS Messaging
SQS, SNS, EventBridge and Kinesis: what each does and when to pick it.
Pick the right service
| Need | Service |
|---|---|
| Work queue, decouple producer/consumer, buffer load | SQS |
| Fan-out one message to many subscribers | SNS (often SNS → many SQS) |
| Route events by content, SaaS/AWS events, schedules | EventBridge |
| Ordered, replayable high-throughput stream | Kinesis / MSK (Kafka) |
| Multi-step workflow with state | Step Functions |
SQS
| Standard | FIFO | |
|---|---|---|
| Throughput | nearly unlimited | 300 msg/s (3k batched; higher with high-throughput mode) |
| Ordering | best effort | strict per MessageGroupId |
| Delivery | at-least-once (duplicates possible) | exactly-once processing (dedup 5 min) |
- Visibility timeout: message hidden while a consumer works; set > processing time (Lambda: ≥ 6x function timeout).
- DLQ via redrive policy after
maxReceiveCountfailures; redrive back once fixed. - Long polling (
WaitTimeSeconds=20) cuts empty receives and cost. - Retention 1 min – 14 days; message ≤ 256 KB (use S3 pointer for bigger).
- Delay queues / per-message delay up to 15 min.
SQS + Lambda
- Event source mapping polls and invokes with batches (up to 10k / 5 min window).
- Return
batchItemFailuresto retry only failed messages (partial batch response). - Scale: up to concurrency limit; set
MaximumConcurrencyon the mapping to protect downstream.
export const handler = async (event) => {
const failures = [];
for (const r of event.Records) {
try { await process(JSON.parse(r.body)); }
catch { failures.push({ itemIdentifier: r.messageId }); }
}
return { batchItemFailures: failures };
};SNS
- Pub/sub topic; push to SQS, Lambda, HTTP(S), email, SMS, Firehose.
- Filter policies on subscriptions so each consumer gets only relevant messages.
- FIFO topics pair with FIFO queues for ordered fan-out.
- Fan-out pattern: SNS topic → multiple SQS queues → independent consumers with their own retries/DLQs.
EventBridge
- Event bus (default, custom, partner/SaaS); rules match on event pattern → up to 5 targets per rule.
- Content-based filtering, input transformation, archive & replay, schema registry.
- Scheduler for cron/one-time jobs; Pipes connect source → filter → enrich → target.
{ "source": ["orders.service"],
"detail-type": ["OrderPlaced"],
"detail": { "total": [{ "numeric": [">", 100] }] } }Kinesis Data Streams
- Shards (1 MB/s or 1000 rec/s in, 2 MB/s out each), or on-demand mode.
- Ordered per partition key; retention 24 h – 365 days; multiple consumers can replay.
- Firehose: managed delivery to S3/Redshift/OpenSearch with buffering.
Reliability patterns
- Idempotent consumers: dedupe on message/event id (DynamoDB conditional put).
- DLQs + alarms on
ApproximateNumberOfMessagesVisibleand DLQ depth. - Backoff with jitter on retries.
- Transactional outbox to publish events consistently with DB writes.
- Watch
ApproximateAgeOfOldestMessagefor consumer lag.