Fundamentals of Distributed Systems: CAP Theory, ACID, BASE, Idempotency, and Distributed Transaction Protocols
This article explains core distributed‑system concepts such as the CAP theorem, ACID and BASE transaction models, idempotent design, and various distributed transaction mechanisms including two‑phase and three‑phase commit, TCC/Saga compensation, message‑based transactions, and popular frameworks like JDTS and Seata.
CAP Theory : Consistency means all replicas hold the same state at any moment; Availability ensures the system responds correctly even when some nodes fail; Partition tolerance guarantees service continuity despite network partitions.
Local Transaction ACID Properties : Atomicity – all operations succeed or none; Consistency – data satisfies integrity constraints before and after; Isolation – concurrent transactions do not interfere; Durability – once committed, data persists.
BASE Theory : Basically Available – core services remain functional during failures; Soft State – data may be in intermediate states without affecting overall availability; Eventually Consistent – data will become consistent after a bounded time. BASE sacrifices some strong consistency to gain higher availability compared to ACID.
Idempotency Design : An operation is idempotent if repeated executions with the same parameters produce the same result, e.g., calling orderProcess() multiple times deducts inventory only once and returns true.
Distributed Transaction Classification – Two‑Phase Commit (2PC) and Three‑Phase Commit (3PC) : 3PC adds a timeout mechanism for both coordinator and participants and inserts a preparation phase between the first two phases, reducing resource locking and blocking time. However, it incurs performance overhead and can cause long lock durations.
Compensation Transactions – TCC and Saga : Both use a compensation (undo) operation for each action, requiring idempotent design. They simplify error handling but increase code size and reduce maintainability.
Message Transactions : Consistency is achieved by wrapping local operations and message sending in a single transaction, ensuring both succeed or fail together. Downstream services consume the message to perform corresponding actions, achieving eventual consistency. Example product: RocketMQ.
Distributed Transaction Product Frameworks
JDTS : Provides high‑availability services where any node can handle requests; supports horizontal and vertical scaling.
Seata : Open‑source solution offering AT, TCC, SAGA, and XA modes for a one‑stop distributed transaction platform.
Global Transaction Service (GTS) : Enables high‑performance transaction consistency across micro‑services, integrating with databases (RDS, MySQL, PostgreSQL), RPC frameworks (Spring Cloud, Dubbo, HSF), and message queues to support distributed, multi‑database, message, and service‑chain transactions.
JD Retail Technology
Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.