Post office, loudspeakers and city gates
A society needs infrastructure for communication: post offices for letters, loudspeakers for announcements, and gates where visitors enter. In AWS these are SQS, SNS and API Gateway.
The post office: SQS
Every human that does background work should have an inbox (an SQS queue):
| Feature | Human meaning |
|---|---|
| Messages wait until processed | Letters stay in the box until read |
| Visibility timeout | While you're reading a letter, nobody else gets it |
| Retries | If you fail to handle it, it goes back in the box |
| Dead-letter queue | After several failures, the letter goes to a "problem letters" box for a person to examine |
| FIFO queues | Strict order and no duplicates, when sequence matters |
Connecting an inbox to a Lambda function in CDK:
import { SqsEventSource } from "aws-cdk-lib/aws-lambda-event-sources";
chefCookFn.addEventSource(new SqsEventSource(chefInbox, {
batchSize: 10,
reportBatchItemFailures: true, // only failed letters are retried, not the whole batch
}));
Always alarm on messages in a dead-letter queue. A growing pile of problem letters means customers are silently being let down.
Loudspeakers: SNS
SNS pushes one message to many subscribers at once — queues, functions, email, SMS, mobile push. Use it for:
- Fan-out to multiple queues (each listener gets its own copy).
- Notifications to people — alerts to the on-call engineer, SMS to customers.
EventBridge and SNS overlap; as a rule of thumb, EventBridge is the town square for events between services (rich filtering, many targets, archive/replay), while SNS is the loudspeaker for very high fan-out and direct notifications.
The city gate: API Gateway
Outsiders — customers' phones, the web UI, partners — enter through a gate. Amazon API Gateway is that gate:
| Gate duty | Feature |
|---|---|
| Check identity | JWT authorizers (Cognito), IAM, Lambda authorizers |
| Control crowds | Throttling, usage plans per partner |
| Direct visitors | Routes to the right human (/orders → Waiter, /payments → Cashier) |
| Speak many languages | REST/HTTP APIs and WebSockets |
| Keep a register | Access logs |
One gate for the whole society (a shared HTTP API with routes per human) is simple and cheap. Large societies sometimes give each human its own API and put a domain name in front of all of them.
The society's senses: the UI
The UI is how the whole society perceives the outside world — the menu customers see, the button they press, the QR code they scan. It isn't a human itself; it's the sensory surface that turns people's actions into requests and events.
| UI hosting | Serverless option |
|---|---|
| Static website (React, Vue, plain HTML) | S3 + CloudFront |
| Full-stack web with CI/CD | AWS Amplify Hosting |
| Live updates (order status) | API Gateway WebSockets or AppSync subscriptions |
Visitors who can't wait vs those who can
- If a visitor needs an answer now (price check, order confirmation), route the gate to a human that responds quickly.
- If the request triggers long work, accept it, return a reference ("order #42 received"), drop a letter in a queue, and let the UI poll or receive a push when it's done.
Letters (SQS) carry work reliably, loudspeakers (SNS) broadcast, the town square (EventBridge) shares facts, and the gate (API Gateway) decides who may enter — together they make a society that stays calm under pressure.