SShortSingh.
Back to feed

CAP Theorem Explained: Why Distributed Systems Must Choose Between Consistency and Availability

0
·1 views

The CAP theorem, formally proven by Gilbert and Lynch in 2002, states that a distributed system cannot simultaneously guarantee linearizable consistency, full availability, and partition tolerance. Since network partitions are inevitable in real-world systems due to hardware failures, GC pauses, and link drops, partition tolerance is effectively a mandatory constraint rather than a choice. The real design decision is whether a system sacrifices consistency or availability when a partition occurs, and making the wrong choice can cause issues like double charges or unnecessary downtime. CP systems such as etcd use quorum-based writes and refuse requests when quorum is lost, while AP systems like Cassandra allow writes during partitions and resolve conflicts after healing. Brewer himself clarified in 2012 that CAP trade-offs apply per operation, not per system, meaning a single service can be CP for payments and AP for less critical operations like view counts.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Apache Ossie Joins ASF Incubator to Standardize Business Data Definitions

A new project called Apache Ossie, formerly known as the Open Semantic Interchange, entered the Apache Software Foundation Incubator in June 2026. The initiative aims to standardize how organizations define business metrics and data concepts, a problem the data industry has long struggled to solve. Dremio, Snowflake, and dbt Labs are named as core developers behind the project. The lack of shared definitions often causes different teams to report conflicting figures for the same metric, a phenomenon known as semantic drift. The project's arrival is seen as especially timely given the rise of AI agents that query business data directly and have no reliable way to determine which definitions a company considers authoritative.

0
ProgrammingDEV Community ·

How a 20,000-Line Legacy Map Editor Was Rebuilt With Cleaner Architecture

A workspace management platform underwent a full rewrite of its interactive office map editor, which had grown to nearly 20,000 lines of TypeScript across 230 files over several years. The original editor, rooted in the AngularJS era, suffered from a monolithic structure where a single component handled everything from rendering to event management, creating an infinite animation loop even when idle. Rather than a risky all-at-once migration, the team built a new administration module in parallel, retaining Fabric.js while restructuring the codebase into focused subsystems — Viewport, Object Registry, and Changes Tracker — each with a single responsibility. A key architectural decision to move the camera via Fabric's viewportTransform, rather than repositioning objects, simplified zooming, panning, exporting, and printing simultaneously. Unexpectedly, implementing high-quality map printing proved more challenging than the rewrite itself, as browser-native printing produced blurry output and leaked editor UI elements into the printed document.

0
ProgrammingDEV Community ·

Why Every Request Log Line Needs a Request ID for Production Debugging

Effective request logging in backend services requires more than basic console output — each log line must carry a unique request ID to trace a request across multiple services and async operations. Without a correlation ID such as requestId or traceId, logs from high-throughput services become an unreadable mix of interleaved entries, making it impossible to diagnose failures. Structured logging, where each line is a JSON object with consistent fields, combined with a propagated correlation ID, enables queryable logs instead of blind text searches. In Node.js, the pino library is a common choice for structured logging, with Fastify offering built-in pino integration and automatic request ID generation, while Express requires manual setup via the pino-http middleware. Both frameworks share the same failure point when correlation IDs are dropped between services, making consistent ID propagation across HTTP calls and async work a critical part of any logging strategy.

0
ProgrammingDEV Community ·

Why Async Errors Silently Crash Express 4 Apps and How Fastify Handles Them

In Express 4, async route handlers return a Promise before it settles, meaning the framework's synchronous try/catch block cannot intercept a later rejection. When that Promise rejects, Node.js emits an unhandledRejection event instead of routing the error to Express middleware, and since Node 15 this can crash the entire process by default. The standard fix in Express 4 is an asyncHandler wrapper that explicitly chains .catch(next), forwarding rejections into the error middleware chain. Express 5, released as a stable major version in 2024, resolves this at the framework level by automatically forwarding rejected Promises into the error chain without any wrapper. Fastify avoids the problem altogether by natively awaiting each handler in its pipeline, catching rejections and routing them through its setErrorHandler for consistent JSON error responses.