惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News | PayPal Newsroom
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
SecWiki News
SecWiki News
Know Your Adversary
Know Your Adversary
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
NISL@THU
NISL@THU
WordPress大学
WordPress大学
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threat Research - Cisco Blogs
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
Security Archives - TechRepublic
Security Archives - TechRepublic
有赞技术团队
有赞技术团队
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
V
V2EX
G
GRAHAM CLULEY
TaoSecurity Blog
TaoSecurity Blog
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
Latest news
Latest news
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
S
Schneier on Security
I
Intezer
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
爱范儿
爱范儿
The Register - Security
The Register - Security
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
美团技术团队
B
Blog RSS Feed

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
System Design - 6.CAP Theorem & PACELC, CAP Theorem & PACELC: The Most Important Trade-off in Distributed Systems
Rajkiran · 2026-05-31 · via DEV Community

The Theorem That Changed How We Think About Databases
In 2000, Eric Brewer stood at a conference and proposed a conjecture that would reshape distributed systems forever:

"You can only guarantee two of these three properties at the same time: Consistency, Availability, and Partition Tolerance."

Two years later, Seth Gilbert and Nancy Lynch proved it mathematically. It became known as the CAP Theorem — and every distributed system architect since has had to wrestle with it.
It sounds abstract. But once you understand it, you'll never look at a database choice the same way again. You'll understand why Amazon DynamoDB and Google Spanner make opposite architectural choices. You'll know why your bank uses PostgreSQL while Twitter uses Cassandra.
Let's break it down from first principles.

The Three Properties
C — Consistency
Every read receives the most recent write, or an error. There's only one version of the truth — all nodes agree.

Not the same consistency as ACID. CAP consistency (linearizability) means every read reflects the latest write across all nodes. ACID consistency means transactions don't violate database constraints. Different concepts, same confusing word.

A — Availability
Every request receives a non-error response — though it might not be the most recent data. The system is always up and answering.

Note: "Available" in CAP doesn't mean "fast." It means "responds without error." A system that always returns a (possibly stale) answer is Available.

P — Partition Tolerance
The system continues operating even when network messages between nodes are lost or delayed. A partition is when part of your distributed system can't communicate with another part.

The Unavoidable Truth: P Is Not Optional
Here's the insight that makes CAP actually useful:
In any real distributed system, partitions will happen. Networks fail. Cables get cut. Data centers lose connectivity. AWS regions go down.
Since you must tolerate partitions (or have a single-server system, which doesn't scale), the real choice is:
When a partition happens, do you choose:
→ Consistency (refuse to respond rather than return stale data)?
→ Availability (respond with potentially stale data rather than error)?
CAP is really CP vs AP.

CP Systems: Consistency + Partition Tolerance
A CP system chooses to return an error (or block) during a partition rather than return potentially inconsistent data.
The behavior:
Node A and Node B are partitioned (can't communicate).

User writes to Node A: balance = $500
User reads from Node B:
→ CP system: "I can't confirm this is current. Returning error."
→ User gets error, but data is never wrong.
Real CP systems:
HBase — used for large-scale analytics (Facebook messages, LinkedIn activity data). During a partition, HBase refuses reads/writes to maintain consistency. Brief unavailability is acceptable because data correctness is critical.
ZooKeeper — the distributed coordination service used by Kafka, Hadoop, and many others for leader election and configuration management. If ZooKeeper can't reach a quorum of nodes, it stops responding. This is intentional — a misconfigured cluster is worse than a temporarily unavailable one.
MongoDB in strong mode — with writeConcern: majority, MongoDB behaves as a CP system. Writes must be acknowledged by a majority of nodes before succeeding. If nodes can't reach quorum, writes fail.
When to choose CP:

Financial transactions (cannot show wrong balance)
Inventory systems (cannot oversell the last seat)
Distributed locks (cannot have two nodes think they hold the same lock)
Any system where incorrect data is worse than no data

AP Systems: Availability + Partition Tolerance
An AP system chooses to always respond — even if the data might be stale — during a partition.
The behavior:
Node A and Node B are partitioned (can't communicate).

User writes to Node A: tweet posted
User reads from Node B:
→ AP system: "I'll return what I have." Returns feed without latest tweet.
→ User gets a response. Data might be slightly out of date.

Real AP systems:
Cassandra — designed from the ground up for AP. During a partition, Cassandra keeps serving reads and writes from available nodes. Data eventually syncs when the partition heals. Facebook built their Inbox search on Cassandra. Instagram's feed uses it. The brief staleness is acceptable because showing a tweet 2 seconds late is better than a 500 error.
CouchDB — designed for offline-first applications. Phones with intermittent connectivity can still read and write. When connectivity resumes, changes sync and conflicts are resolved.
DynamoDB (default mode) — Amazon's flagship NoSQL service defaults to eventual consistency. Writes succeed as long as one node is available. This is by design — Amazon's shopping cart research showed that availability matters more than momentary consistency for e-commerce.

When to choose AP:

  • Social media feeds (slightly stale is fine)
  • Shopping cart contents (show something rather than error)
  • DNS lookups (stale IP for a short time is OK)
  • Any "best effort" data where brief staleness is acceptable

The Amazon Shopping Cart Study (A Case Study in AP)
Amazon's 2007 Dynamo paper describes a fascinating design decision:
They observed that when customers added items to their cart, the worst experience was an error ("could not add to cart — try again"). The second worst experience was the cart appearing empty.
Temporary inconsistency — adding an item and briefly not seeing it — was actually less bad than an error from the user's perspective.
So DynamoDB was built as an AP system. When two versions of your cart conflict (you added on desktop while your phone was offline), Dynamo keeps both versions and presents them to the application to merge. That's why you sometimes see duplicate items in your Amazon cart — it's the conflict merge surfacing.

_The insight: _ Availability vs Consistency isn't a technical preference. It's a business decision. What does your user experience most when things go wrong?

PACELC: The Extension CAP Forgot
CAP only describes what happens during a partition. But partitions are rare events. What about the other 99.9% of the time, when the network is healthy?
In 2012, Daniel Abadi proposed PACELC to fill this gap:
If Partition → choose between Availability (A) or Consistency (C)
Else (no partition) → choose between Latency (L) or Consistency (C)

Written as: PAC/ELC
The insight: even without a partition, you face a trade-off. To guarantee consistency without a partition, you still need coordination — nodes must agree before returning. That coordination costs latency.

PACELC classifications of real systems:
Reading the table:

  • 1. PA/EL systems (DynamoDB, Cassandra): sacrifice consistency for availability and speed in all situations
  • 2. PC/EC systems (HBase, Spanner): maintain consistency in all situations, paying in latency

How to "Cheat" CAP with Read Replicas
Here's a popular interview question: "Can you have both strong consistency and high availability?"
Technically no, per CAP. But in practice, you can get very close with a common architecture:
Read replicas with routing logic:
Write path: User → Primary DB (strongly consistent write)
Read path: User → Read from Primary (always consistent)
OR
User → Read from Replica (faster, eventually consistent)
You let the application decide per operation:

  • Payment confirmation: read from Primary → strong consistency
  • User profile display: read from Replica → eventual consistency, faster

PostgreSQL, MySQL, and most relational databases support this pattern. The application routes sensitive reads to the primary and non-sensitive reads to replicas.

This isn't "beating" CAP — you're still making the CP choice for critical reads (by always hitting the primary). But for non-critical reads you get near-AP performance. It's a practical hybrid.

Choosing CP or AP for an E-Commerce Cart

This is a classic interview scenario. Here's how to think through it:
The question: "Should the shopping cart be CP or AP?"
Wrong answer: "CP, because we need consistency."
Right answer (think through the user scenarios):

Scenario A: User adds item, gets error due to partition
→ User is frustrated, might leave the site
→ Business cost: potential lost sale

Scenario B: User adds item, briefly doesn't see it (AP staleness)
→ User might be confused but the item is actually saved
→ Business cost: minor confusion

Scenario C: User adds item, sees different items on refresh (inconsistency)
→ More confusing, but still recoverable
→ Business cost: confusion, possible support ticket
Amazon's conclusion: AP wins for cart. The cost of availability failures (errors) is higher than the cost of consistency failures (brief staleness).
But: The checkout step must be CP. When you confirm a purchase and deduct inventory, that must be consistent. You can't sell the last item twice.

The pattern: Use AP for browsing and cart management. Use CP for checkout and payment. Different consistency requirements for different operations within the same system.

Why PACELC Matters More Than CAP for Modern Design
CAP is conceptually important but PACELC is more actionable because:

  1. Partitions are rare. Your system spends 99.9% of its time in the "no partition" state. The ELC part (latency vs consistency) is your everyday trade-off.
  2. CAP doesn't tell you about latency. Two CP systems can have wildly different latencies. Spanner achieves global strong consistency in ~10ms. A naive 2-phase commit might take 500ms. PACELC captures this.
  3. PACELC drives database selection more precisely. "I need PA/EL" → Cassandra or DynamoDB. "I need PC/EC" → Spanner or HBase. CAP alone doesn't give you this resolution.

Key Takeaways

  • CAP theorem: in a distributed system, you can only guarantee 2 of 3 — Consistency, Availability, Partition Tolerance.
  • P is mandatory in real distributed systems. The real choice is always CP vs AP.
  • CP systems (HBase, ZooKeeper, Spanner) refuse to answer during partitions rather than return stale data.
  • AP systems (Cassandra, DynamoDB, CouchDB) always respond, even if data might be stale.
  • PACELC extends CAP: even without a partition, you trade latency (L) vs consistency (C). Most systems are PA/EL or PC/EC.
  • The right choice is a business decision, not a technical preference. What hurts your users more — wrong data or no data?
  • You can build practical hybrids: AP for browsing, CP for payment. Route reads to primary for strong consistency, to replicas for speed.