1.0 Introduction: The Inescapable Laws of Distribution#
Version 1.0 of this series laid the groundwork, defining the roles, tools, and initial architectural patterns of backend engineering. We explored monoliths and microservices, SQL and NoSQL, REST and GraphQL. That knowledge represents the necessary foundation for building functional applications. This volume, however, is about what happens when we scale those applications; when our single server becomes a fleet, our single database becomes a cluster, and our in-process calls become network hops. This is the realm of distributed systems, and it is governed by a different, harsher set of rules.
The transition from a single-machine system to a distributed one is not a linear increase in complexity; it is a paradigm shift. Assumptions that hold true on a single machine; reliable networking, zero latency, instantaneous operations; are shattered. The primary goal of the advanced backend engineer is to build systems that can function correctly and reliably despite the inherent unreliability of the underlying environment.
In the 1990s, L. Peter Deutsch and others at Sun Microsystems compiled a list of fallacies; assumptions that programmers new to distributed applications invariably make, to their peril.
CAUTION
The network is reliable. (It is not.)
Latency is zero. (It is not.)
Bandwidth is infinite. (It is not.)
The network is secure. (It is not.)
Topology doesn’t change. (It does.)
There is one administrator. (There are many.)
Transport cost is zero. (It is not.)
The network is homogeneous. (It is not.)
Every pattern, protocol, and architecture discussed in this volume is, in some way, a strategy for mitigating the consequences of these fallacies.
In a single-server application with one database, data consistency is largely solved via ACID transactions. In a distributed system, consistency becomes one of the most difficult challenges.
2.1 The Consistency Spectrum and the PACELC Theorem#
The CAP theorem describes behavior during network partitions, but the PACELC theorem provides a more complete picture:
NOTE
“If there is a Partition (P), a distributed system must choose between Availability (A) and Consistency (C). Else (E), when the system is running normally, it must choose between Latency (L) and Consistency (C).”
This forces nuanced architectural discussion. A system might sacrifice consistency for availability during failures but prioritize consistency over latency during normal operation.
Two-Phase Commit is synchronous and unsuitable for microservices. The Saga Pattern manages data consistency across services through local transactions and compensating actions.
TIP
Order Service: Creates order in PENDING state, publishes ORDER_CREATED event
Payment Service: Processes payment, publishes PAYMENT_PROCESSED on success
Inventory Service: Updates stock, publishes INVENTORY_UPDATED on success
Order Service: Updates order to CONFIRMED
Failure Handling: If inventory fails, Payment Service compensates with refund, Order Service cancels.
Implementation Styles:
NOTE
Choreography: Services publish/subscribe to events with no central coordinator
Orchestration: Central orchestrator manages saga state and compensating transactions
Write-Through: Cache updates synchronously update DB
Write-Back: Cache updates asynchronously flush to DB
Thundering Herd Mitigation:
CAUTION
When cached item expires, thousands of requests simultaneously miss cache and overwhelm DB. Solution: lock-based re-fetching where only first request loads data while others wait.
Version 2.0 has journeyed into distributed systems engineering. Building resilient, scalable backend systems requires deep understanding of fundamental trade-offs: latency versus consistency, availability versus correctness, speed versus safety.
The advanced backend engineer designs for failure, assumes network hostility, and applies patterns like Sagas, Event Sourcing, Circuit Breakers, and Service Meshes. The ultimate skill is reasoning about complexity; identifying failure points, bottlenecks, and vulnerabilities to apply appropriate mitigation strategies.
Advanced Backend Engineering - From Distributed Systems to Resilient Architectures