SysPad › Examples › 3-tier web app
3-tier web app
A modern web stack: edge network, load balancer, API on Kubernetes, cache, database, and a payments API.
The basics, plus a grouped Data Layer you can collapse.
- Load: 2,000 req/sec
- First to saturate: Nothing at this load
- Estimated cost: $2,058/mo
How it works
- Cloudflare Edge
- The first thing a request meets. Seven in ten are answered here from cache, so everything drawn after it only ever sees the other three.
- Load Balancer
- Spreads requests across the API pods and hides a failed one from users. It also terminates TLS, which is why it sits in the path rather than off to the side.
- API Service
- Where your code runs. Each copy, called a pod, handles 400 requests a second: 10 threads at 25 ms a request. The autoscaler stops at 10 pods, so Max RPS is 4,000. A bigger instance type does not raise it. Try m6i.large: 3 worker nodes then hold only 9 pods, and Max RPS drops to 3,600.
- Session Cache
- Session data, kept in memory so a lookup skips the database. Nine in ten lookups are found here. This diagram does not send the misses on to the database, so changing the hit rate does not change the database load.
- PostgreSQL DB
- The busiest part of this design, at 60%. Reads go to the 2 read replicas: 480 a second, with room for 800. Writes go to the primary: 120 a second, with room for 400. So reads run out first. Set Read replicas to 1, or Target RPS to 3,400, and rerun to watch it saturate.
- Payments API
- Someone else's system. Its latency is added to yours and its rate limit becomes yours during a spike, which is why it is worth drawing rather than assuming.
Lessons for this architecture
- How Cloudflare works
- How Application Load Balancer works
- How EKS Cluster works
- How Amazon ElastiCache works
- How RDS works