A traffic spike rarely stresses every part of a website equally. Static assets may be served comfortably while a database connection pool fills, a cache expires, or one expensive endpoint consumes the application workers.
The first architecture decision is therefore diagnostic: which resource limits useful throughput, and what happens when it reaches that limit? Load balancing, caching, and scaling become more effective when each has a specific job.
1. Load Balancing:
A load balancer distributes requests across application instances. Round-robin is simple; least-connections can be useful when request durations vary; affinity can help when a session depends on a particular instance. NGINX’s load-balancing documentation describes these approaches and their tradeoffs.
Distribution is only one part of the design. Check whether a worker is ready to accept traffic, drain connections before removing it, and account for persistent sessions. Adding workers does not create database capacity if every worker immediately opens more connections to the same constrained database.
2. Auto Scaling:
Auto scaling changes capacity in response to measured demand. Choose a signal that corresponds to the workload: concurrency, queue age, request rate, or resource saturation may be more useful than CPU alone.
Include the time required to start an instance, load data, and warm caches. A sudden burst can arrive faster than capacity becomes available. Maintain appropriate headroom, test scaling limits, and verify that dependencies can support the additional workers. Scale-in should also allow in-flight work to finish.
3. Content Delivery Network (CDN):
A CDN can serve cacheable content closer to users and reduce requests to the origin. It is especially useful for versioned images, stylesheets, scripts, and public pages that tolerate a defined period of staleness.
The cache policy matters as much as the network. Define cache keys, expiration, and invalidation deliberately. Personalized responses must not become shared public cache entries. Measure the hit ratio and origin traffic together; a CDN that mostly forwards requests will not remove an origin bottleneck.
4. Caching:
Cache the result of expensive work when reuse is likely and the permitted staleness is understood. A browser cache, a CDN cache, an application cache, and a database cache operate at different points in the request path.
Document what invalidates an entry and what happens on a miss. If many requests rebuild the same expired value at once, a cache can turn into a burst generator. Request coalescing, staggered expirations, or carefully bounded stale responses may help. Evaluate those choices against the correctness requirements of the data.
5. Database Optimization:
Begin with slow-query evidence, query plans, indexes, and the amount of data returned. Removing an unnecessary query or an unbounded scan can be more valuable than adding application servers.
Use bounded connection pools so that a traffic surge cannot create unlimited database work. Read replicas may help read-heavy workloads, with replication lag and consistency requirements taken into account. Partitioning or sharding can be appropriate later, but they add routing, rebalancing, and cross-partition query costs. They should solve a measured problem.
6. Server Optimization:
Reduce avoidable work on the request path. Compress suitable responses, serve appropriately sized images, reuse connections, and move expensive non-interactive tasks to background processing where the product allows it.
Profile before rewriting. A system can be limited by CPU, memory allocation, disk I/O, lock contention, or a remote service. Response size and browser rendering also affect the user experience even when server processing is fast.
7. Microservices Architecture:
Separate services when independent scaling, ownership, or isolation justifies the extra communication. A service boundary adds network calls, deployment coordination, telemetry, and failure modes. It does not make the same work cheaper simply by moving it elsewhere.
A well-structured application can handle substantial traffic without becoming a collection of microservices. Choose boundaries around responsibilities and measured scaling needs, then ensure each new dependency has a timeout and an understood failure response.
8. DNS Load Balancing:
DNS routing can direct clients toward different endpoints or regions. It is useful for broad traffic distribution, but resolvers and clients cache answers. A DNS change therefore does not guarantee an immediate move for every user or an existing connection.
Plan health detection and failover at the application and network layers as well. Test what clients actually do when an endpoint fails rather than assuming they will instantly request a new address.
Additional controls: admission, isolation, and recovery
The remaining techniques fit around those core mechanisms:
| Technique | Useful purpose | Limit to account for |
|---|---|---|
| Traffic shaping and rate limits | Bound demand and protect important operations | Limits need a clear policy and client response |
| Virtual machines and containers | Package workloads and isolate resources | Packaging does not add capacity to the underlying host |
| Edge computation and geographic routing | Move suitable work closer to users | Data location and consistency can constrain placement |
| Failover systems | Continue service after a component or region fails | Standby capacity and recovery procedures need testing |
| Circuit breakers and bounded queues | Stop overload spreading between services | Rejected or delayed work needs an explicit product behavior |
| Web application firewalls | Filter selected malicious request patterns | A WAF does not replace capacity planning or application security |
Retries deserve particular attention. Retrying every failed request immediately can multiply load on a struggling service. Timeouts, limited retries, backoff, and jitter help control that feedback loop. Operations with side effects need an idempotency strategy; a timeout does not prove that the first attempt did nothing. The AWS Builders’ Library explains these failure patterns.
Validate the architecture under realistic load
Test representative reads, writes, cache misses, and slow dependencies. Track throughput, latency percentiles, errors, queue depth, and resource saturation together. A test that reports only successful requests per second can miss a growing backlog.
Run long enough to expose memory growth and periodic work. Then remove a worker or slow a dependency and observe whether the system degrades in the way intended. The useful result is a capacity boundary and a recovery plan, not a promise that the architecture can absorb unlimited traffic.