App server (monolith)
EC2 Auto Scaling group / ECS / Elastic Beanstalk
One deployable that contains every module: auth, catalog, orders, payments, notifications.
In a monolith
The whole backend
All modules share one codebase, one process and one connection pool. Module-to-module calls are function calls: nanoseconds, no network, one transaction.
In a distributed system
Strangled into services
Modules get extracted into services over time (strangler fig). Every extraction turns a function call into a network call.
On AWS
EC2 Auto Scaling group / ECS / Elastic Beanstalk
Run N identical instances in an Auto Scaling group behind an ALB, spread across AZs — or containerise it on ECS/Fargate.
- EC2 Auto Scaling group$$Classic VMs; you patch the OS; scale on CPU or request count
- ECS on Fargate$$Containers without managing servers
- Elastic Beanstalk$$PaaS wrapper: ALB + ASG + deploys configured for you
- Lambda$Possible for small apps; cold starts, 15-minute limit, DB connection spikes
- Reach for it when
- Day one. A monolith is the right default until team size or wildly different scaling needs force a split.
- What it costs you
- One bad deploy or memory leak takes down every feature
- Scaling means scaling everything, even the idle parts
- Large teams step on each other in one codebase
- When it dies
- Every module dies together: a crash in payments takes browsing down too. With 2+ instances behind an LB, one instance dying is a non-event.
Interview follow-ups
Is a monolith “bad”?
No. It’s simpler to build, test, deploy and debug, and most scaling moves (LB, cache, replicas, CDN, queues) work fine with it. Split when team autonomy or independent scaling/deploys justify the network cost.
What must change before running multiple instances?
Make it stateless: sessions in Redis/DB or signed tokens, files in object storage, no in-memory state that must be shared.
What is the strangler fig pattern?
Route one capability at a time to a new service (via the LB/gateway) while the rest stays in the monolith, until the monolith is small or gone.
Connection rules
It talks to
- Load balancer
- NAT gateway
- App server
- Service
- Realtime server
- Workflow
- SQL database
- Read replica
- NoSQL store
- Cache
- Object storage
- Search
- DB proxy
- Queue
- Pub/sub topic
- Event stream
- Identity provider
- Secrets
- Third-party API
- API gatewayOnly when: Calling another team’s public API or a partner API that only exists behind a gateway.
Gets traffic from
- DNS
- CDN
- Load balancer
- API gateway
- Service
- Worker
- Realtime server
- Workflow
- Queue
- Pub/sub topic
- Event stream
- ClientsOnly when: There is exactly one instance (early stage: DNS points at the server). With two or more instances, put a load balancer or gateway in front so clients don’t need to know which server to hit.
- Third-party APIOnly when: A single-instance webhook receiver; normally webhooks come in through your LB or gateway.
Never
- App server → CDNYour code doesn’t send traffic to the CDN — the CDN pulls from origins.
- App server → WorkerDon’t call workers directly — enqueue a job.
- App server → DLQProducers publish to the main queue; the broker moves failures to the DLQ.