Architecture and system design
Software architecture and system design: styles and building blocks
Monolith, microservices, serverless and event-driven styles, plus load balancers, caching, queues, CDN, replication and sharding. When to use each, trade-offs and diagrams.
Architecture styles
- MonolithThe whole application lives in one codebase and ships as one deployable artifact. The simplest and cheapest starting point for most products.
- Modular monolithOne deployable, but inside it clear modules with their own data and a public API. You get the order of microservices without their network cost.
- MicroservicesA system of many small services, each with its own database and independent deploys. It solves the large team problem at the cost of complex operations.
- Serverless architectureCode runs as functions in response to events, while the cloud handles servers, scaling and idle time. You pay for invocations, not for machines that wait.
- Event-driven architectureServices publish events about what happened, and others subscribe and react. The producer does not know its consumers, so the system is easy to extend.
- CQRS and Event SourcingCQRS splits the write model from the read model, and Event Sourcing stores not the current state but the full sequence of events. Together they give full history and fast reads at the cost of complexity.
- Monolith vs microservices vs serverlessA comparison of three approaches by cost, team size, deploys, scaling, data consistency, debugging and latency. Plus a simple decision path.
Building blocks
- Load balancerSpreads requests across several copies of a service and takes failed ones out of rotation. The first step to horizontal scaling and zero downtime deploys.
- CachingStores the results of expensive operations in fast storage so they are not computed again. The cheapest way to speed up reads, as long as you decide correctly when the cache goes stale.
- Message queueA buffer between whoever creates work and whoever does it. It lets you answer the user right away and do the heavy job in the background with retries.
- CDNA worldwide network of servers that caches your content closer to users. It cuts latency from hundreds of milliseconds to tens and takes traffic off the origin.
- Database replicationCopies data from the primary database to one or more replicas. It scales reads and enables fast recovery after a failure, but introduces replication lag.
- ShardingSplits data across several independent databases by a key to scale writes and volume. The last resort when replicas, a cache and a bigger server are no longer enough.
- API gatewayA single entry point for clients in front of a set of services. It handles routing, authentication, limits and logging so each service does not do it on its own.
- Rate limitingCaps the number of requests from one client over a period of time. It protects the system from overload, abuse and costly bugs in other people's code.
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).