← All posts
LinkedIn
  • #Frontend

The CAP Theorem — But for Frontend Engineers

Every frontend engineer makes CAP Theorem trade-offs daily — most just don't realize it.

When a request is slow, do you block the UI and wait? Or do you show cached data and sync later?

That's not a UX decision. That's a distributed systems decision.

The CAP Theorem says a distributed system can only guarantee two of three properties: Consistency, Availability, and Partition Tolerance.

For frontends, partition tolerance isn't optional — the browser talks to your server over the internet, the most unreliable network there is. So the real choice is always: Consistency or Availability?

I broke this down into a visual guide — swipe through to see how patterns you already use (caching, optimistic UI, spinners, offline mode) map directly to CAP trade-offs.

Curious which side you default to — CP or AP? 👇

Slides

  1. The CAP Theorem — But for Frontend Engineers You already make this trade-off every day. You just don't call it CAP.
  2. A distributed system can only guarantee 2 of 3: - C — Consistency: every read returns the latest write - A — Availability: every request gets a response - P — Partition Tolerance: the system works even when the network fails
  3. The network between the browser and your server is the internet. - Connections drop - Requests time out - Users go offline Partition tolerance isn't a choice. It's the default condition. So the real question is: when the network breaks, do you sacrifice C or A?
  4. When a partition happens, block until the server confirms. What it looks like: - Spinners until data loads - Disabled buttons during submission - Empty screens on timeout When it's the right call: - Payments & checkout - Banking transactions - Anything where showing wrong data is worse than showing nothing
  5. When a partition happens, keep going with local/cached data. What it looks like: - Instant UI updates (sync later) - Offline mode that works - Stale data that refreshes in the background When it's the right call: - Social feeds - Collaborative tools - Content-heavy apps - Anything where responsiveness matters more than real-time accuracy
  6. | Pattern | CAP choice | Behavior | | ------------------------- | ---------- | ---------------------------------- | | Loading spinner | CP | Block until server responds | | Optimistic UI | AP | Update now, confirm later | | cache-first | AP | Serve stale, revalidate async | | network-only | CP | Always fetch fresh data | | stale-while-revalidate | AP | Fast + eventually correct | | Offline-first (IndexedDB) | AP | Fully available, sync on reconnect | | Disabled form until saved | CP | Consistent at the cost of speed |
  7. Treating this as a global, binary decision. The best frontends don't pick CP or AP for the entire app. They pick per feature: - Checkout → CP (correctness matters) - Feed → AP (speed matters) - Collaborative editor → AP + conflict resolution - Account balance → CP (stale data is dangerous)
  8. CA = Consistency + Availability, no Partition Tolerance. This works for a single-node database on a local network. It does not work for a browser talking to a server over the internet. If your system involves a network you don't fully control, CA is off the table.
  9. Every loading spinner is a CP decision. Every optimistic update is an AP decision. You're already making CAP trade-offs. The question is whether you're making them consciously.
  10. If you want know more details and beyond that, have a look on my book: "Micro Frontends Architecture for Scalable Applications" on https://www.vanderleialves.com/micro-frontend-book
See more on LinkedIn ↗