Engineering notes
Scalable Software Engineering: Principles and Patterns
How stateless services, caching, queues, backpressure and load testing work together—and the conditions that make each pattern useful or dangerous.
Scaling patterns redistribute work, state or waiting. They do not remove the underlying work. A cache exchanges freshness for cheaper reads; a queue exchanges immediate completion for deferred processing; replication exchanges coordination and infrastructure cost for capacity. This guide uses a hypothetical document-export product to explain how to choose and combine these mechanisms.
Measure the limiting resource before choosing a pattern
Follow one user operation through the system. An export may spend little time in Python but substantial time scanning rows, waiting for a connection and writing a large file. CPU graphs alone will not reveal that path. Measure successful throughput, latency distributions, query cost, memory, connection wait and queue age against a stated workload.
Use a baseline with realistic data and preserve the business result while optimizing. Replacing a join with a faster query that silently omits records is a correctness regression. Establish expected row counts and invariants before accepting a performance gain. A useful optimization changes the resource that limits the user operation rather than merely making a local function faster.
Conceptual illustration of the topic; not an implementation diagram.
Replicate stateless work and budget shared state
Keep request-specific data in the request context and durable state in a shared store with a defined ownership model. An instance should be replaceable without losing accepted work. Uploads on a container filesystem and in-memory job lists violate that expectation unless their temporary nature is part of the product contract.
Replication increases consumers of downstream resources. Calculate database and HTTP connection limits across every process, including background workers. Scale application and worker fleets separately when their resource profiles differ. A CPU-heavy export should not consume the same concurrency budget as the API that accepts a new job.
Cache with a correctness and invalidation policy
Choose the unit being cached: an immutable asset, a query result or a computed representation. Define who may see it, how long it may be stale and what invalidates it. Tenant-specific data requires tenant-aware keys and server-side authorization; a high cache hit rate does not justify cross-tenant leakage.
Plan for misses. A popular key expiring can send many identical requests to the database. Request coalescing, expiry jitter and stale-while-revalidate can reduce this pressure where stale results are acceptable. Bound cache memory and handle cache failure. If the database cannot survive a cold cache, the cache is part of the availability model and needs corresponding operational treatment.
Use queues with bounded backlog and explicit acknowledgement
Accept an export as a durable job and return its identifier after the acceptance record commits. A worker generates the file, stores it durably and updates job state. Acknowledging before durable completion can lose work; acknowledging afterwards can lead to redelivery if the worker crashes between completion and acknowledgement. Design the operation to tolerate that duplicate.
Specify maximum job age, attempts, execution time and storage retention. Large jobs may need chunking and checkpoints. A retry queue and a dead-letter destination are useful only when someone can diagnose and safely replay their contents. Retaining sensitive document data in messages also creates access and deletion obligations.
Apply backpressure before overload becomes an outage
A system needs admission control as well as workers. Bound queue size and per-tenant concurrency; rate-limit expensive endpoints and return an actionable response when capacity is unavailable. Separate interactive and batch pools so one large customer cannot consume every worker. Fairness is a product decision as well as a scheduling policy.
Retries consume additional capacity. Set a deadline, a maximum attempt count and exponential backoff with jitter for transient failures. Avoid retrying at every layer: nested retries multiply downstream attempts. Do not retry non-idempotent side effects without a durable way to recognize the same operation. Backpressure protects recovery capacity rather than promising that every request will be accepted.
Test the composed system and define a stopping rule
Run steady, burst and sustained-overload scenarios. Then remove a worker, slow object storage and restart from a cold cache. Verify that accepted exports finish or surface a visible failure, tenant isolation remains intact and the backlog drains within the chosen recovery objective. Use an arrival-rate model when you need to expose overload rather than allowing slow responses to lower the offered traffic.
Common mistakes are adding workers to a saturated database, caching without invalidation, treating a dead-letter queue as resolution and measuring only average latency. Stop adding patterns when the measured objectives are met with acceptable cost and operational effort. Record the next capacity threshold so the team knows when to revisit the design.
References and further reading
Related content
Software Modernisation and Performance Optimisation
Architecture review, database tuning and focused software improvements for applications that have become slow, fragile or difficult to change.
Backend Development, APIs and System Design
Backend systems, databases and APIs that connect your interfaces, apply business rules and keep information moving between the tools your team uses.
How to Design Scalable Software Architecture
A practical architecture guide to workload models, data ownership, capacity limits and incremental growth—without introducing distributed complexity before it solves a measured problem.
Apply these decisions to your product
Describe the workload, current constraint and product goal to define the scope of a technical discussion.
Discuss your project
