Cloud patterns
Patterns for distributed systems in the cloud: staying up when parts fail, moving messages, scaling data and shaping the edge.
Resilience
Keep working when a dependency is slow, down or overloaded.
Give each dependency or workload its own limited pool of resources, so one slow part can't use up everything and sink the whole service.
Stop calling a dependency that keeps failing, fail fast with a fallback, and probe now and then to see if it has recovered.
Expose an endpoint that reports whether an instance can do its job, so load balancers, orchestrators and monitors can route around problems.
Automatically try a failed call again after a growing, randomised delay, because many cloud failures are brief and fix themselves.
Cap how many requests each client can make in a time window, and reject the excess politely, to protect your service and keep it fair.
Messaging
Connect services with queues and events, and keep data consistent across them.
Put a translation layer between a new system and a legacy or external one, so the old system's model and quirks don't leak into the new design.
Let several identical workers read from the same queue, each message going to exactly one of them, so processing scales out simply by adding workers.
Publish an event once to a topic and let any number of independent services subscribe to it, without the publisher knowing who they are.
Put a queue between a spiky source of work and the service that does it, so bursts are absorbed and processed at a steady, safe rate.
Run a business transaction across several services as a series of local steps, each with a compensating action that undoes it if a later step fails.
Save a change and the event announcing it in the same database transaction, then publish the event separately, so you never lose or invent events.
Data
Read fast, write safely and grow beyond one database.
Check a fast cache first, load from the database only on a miss, and store the result in the cache for next time.
Use one model to change data and a separate, read-optimised model to query it, so each side can be designed and scaled for its own job.
Store every change as an immutable event in an append-only log, and derive the current state by replaying them, instead of overwriting rows.
Precompute the data a screen or report needs into a ready-made table, and keep it updated, instead of joining and aggregating on every request.
Split one big data set across several databases by a key, such as customer or region, so data and load can grow beyond what one server can handle.
Edge & deployment
Shape what clients see, and change systems without big-bang rewrites.
Put a local helper between an app and the remote services it calls, to handle retries, timeouts, routing and credentials on the app's behalf.
Give clients one entry point that routes requests to the right backend service and handles shared concerns like authentication and rate limits.
Give each kind of client, such as web, mobile or partners, its own thin backend that shapes data exactly for that client.
Let a group of identical instances pick one leader to do work that must happen exactly once, and automatically pick a new one if it fails.
Run supporting features such as proxying, logging or config sync in a separate container next to the app, sharing its lifecycle but not its code.
Serve files that are the same for everyone, such as scripts, styles, images and prerendered pages, from object storage behind a CDN instead of from app servers.
Replace a legacy system piece by piece behind a routing layer, sending more features to the new system over time until the old one can be switched off.
Hand clients a short-lived, narrowly scoped token so they can upload or download files directly from storage, without streaming through your servers.