Distributed System Basics in System Architecture
basic · System Architecture
Distributed System Basics As application traffic grows from a few thousand users to millions, a single server instance will inevitably hit a physical hardware limit (CPU cycles, RAM capacity, or network bus throughput). To scale past this limit, we must transition from single-node computing to Distributed Systems . 1. What is a Distributed System? A Distributed System is a collection of autonomous, independent computing nodes (servers) that are physically separated but connected over a high-speed local network or the internet. To the end-user or client application, the entire cluster behaves and appears as if it were a single, unified computer. Core Mechanics In a distributed system, there is no shared memory or central CPU clock. Instead, nodes communicate entirely by passing messages over network protocols (like HTTP, gRPC, or TCP). The system handles state synchronization, data partitioning, and distributed execution blocks across multiple physical machines concurrently. The Inherent Trade-offs: The CAP Theorem When designing a distributed data store, you are bound by the CAP Theorem , which states that it is mathematically impossible for a distributed system to simultaneously provide more than two of the following three guarantees: THE CAP THEOREM Consistency (C) / \ / \ / PARTITION \ / TOLERANCE \ / (Enforced) \ / \ Availability (A) ───────────────── Partition Tolerance (P) Consistency (C): Every read operation returns the most recent write or an error. All nodes see the exact same data at the same time. Availability (A): Every non-failing node returns a non-error response for every request, though it cannot guarantee it contains the absolute most recent write. Partition Tolerance (P): The system continues to operate despite an arbitrary number of messages being dropped or delayed by the network between nodes. The Reality Check: In a real-world network, communication failures are inevitable (Partition Tolerance is mandatory). Therefore, when a network partition occurs, an architect must choose between Consistency (blocking the request until nodes sync up, sacrificing Availability) or Availability (returning old or stale data immediately, sacrificing Consistency). 2. Vectors of Growth: Scalability Scalability is the measure of a system's ability to handle an increasing volume of requests, data, or concurrent users smoothly by adding more computing resources without degrading overall performance. SCALABILITY PARADIGMS │ ┌────────────────────────────┴────────────────────────────┐ ▼ ▼ Vertical Scaling (Scale-Up) Horizontal Scaling (Scale-Out) • Upgrading a single server machine. • Adding more server machines to a pool. • Hardware limits are absolute. • Unlimited theoretical capacity. • Creates a single point of failure (SPOF). • Requires a network load balancer. A. Vertical Scaling (Scaling Up) Vertical scaling means adding more power to an existing server—upgrading it with a faster CPU, more RAM, or faster NVMe solid-state storage arrays. Pros: Highly simple. It requires no changes to application software architecture, because all processes continue to run inside a single operating system thread. Cons: Hard hardware ceilings exist (you can only buy a motherboard with so many RAM slots). Furthermore, it is incredibly expensive at the high end and maintains a catastrophic Single Point of Failure (SPOF) . B. Horizontal Scaling (Scaling Out) Horizontal scaling means adding more individual servers to your structural pool (e.g., turning 1 large application server into a pool of 10 small servers running behind a load balancer). Pros: Unlimited theoretical growth potential. You can continuously spin up cheap, commodity cloud instances as traffic spikes. Cons: Introduces significant architectural complexity. Your application code must be completely stateless , and you must handle complex data synchronization and network latency across nodes. 3. Surviving Failures: Reliability Reliability is the probability that a system will perform its intended function correctly, without failure, under specified operational conditions for a designated period of time. It focuses on correctness and data safety. Production Mechanics A reliable system expects components to fail. It leverages fault-tolerant design to detect, isolate, and neutralize errors before they can corrupt production data or impact the end-user experience. SQL -- Architectural Math: Measuring Reliability via Mean Time Between Failures -- MTBF = Total Operational Uptime / Total Number of System Failures Engineering Rules for High Reliability Eliminate Single Points of Failure (SPOFs): Ensure every critical component (load balancers, databases, cache layers) has a backup or peer instance ready to take over. Graceful Degradation: If a secondary service fails (e.g., the recommendation engine module crashes), the system should disable that feature but allow the user to complete their primary task (e.g., checking out an order). 4. Keeping Systems Online: Availability Availability is the percentage of time that a system remains fully operational, accessible, and responsive to user requests over a given time window. It focuses purely on uptime . SQL -- Architectural Math: Measuring Uptime Percentage -- Availability = Uptime / (Uptime + Downtime) The Metric of "Nines" In enterprise systems engineering, availability is tracked using standard high-availability brackets known as the "Nines": Availability Bracket Permitted Downtime per Year Target Production Profile 99% ("Two Nines") 3.65 days Standard internal development environments or non-critical tools. 99.9% ("Three Nines") 8.77 hours Standard customer-facing SaaS production applications. 99.99% ("Four Nines") 52.60 minutes Enterprise-grade e-commerce platforms or payment gateways. 99.999% ("Five Nines") 5.26 minutes Mission-critical core banking ledgers or telecommunications infrastructure. The Core Difference Between Reliability and Availability While they sound similar, a system can be highly available but completely unreliable, or vice versa: Scenario A (Available but Unreliable): A web server stays online 99.99% of the time, but due to a software bug, 20% of all user requests return a 500 Internal Server Error . The system is Available (it responds), but Unreliable (it functions incorrectly). Scenario B (Reliable but Unavailable): A secure database transaction service goes down for 2 hours every week for maintenance, but while it is online, it processes transactions with absolute structural correctness and zero data errors. The system is Reliable (it never errs), but lacks High Availability (it has frequent planned downtime). Distributed System Foundations Reference Matrix Metric / Attribute Vector Architectural Focus Primary Design Tooling Primary Operational Failure Mode Scalability Managing structural growth patterns. Horizontal scaling groups, load balancers, database sharding. Performance degradation, high resource bottlenecks, network timeouts. Reliability Ensuring strict operational correctness. Redundancy, failover scripts, health checks, data replication. Logic exceptions, silent data corruption, unhandled edge crashes. Availability Maximizing system runtime uptime. Multi-region cloud deployments, auto-scaling groups, active-passive backups. Complete infrastructure outages, hardware crashes, connectivity drops.