Latest / The CTO Podcast with Fexingo: Technical Leadership, Architecture, and Engineering Org / How Notion Rebuilt Its Block Engine for Hybrid Local-Sync
Transcript
- Lucas: Notion hit 100 million users last year. But if you were using it back in 2020, you remember the collaboration was... bumpy. Edits would lag, occasionally conflict, and if you lost internet, you were basically locked out of your own page. Luna: I remember that. It felt like Google Docs in the early days — you'd type and watch the cursor jump. Lucas: Exactly. The core problem was that Notion was designed as a single-user document store. Each page was a JSON blob with blocks — headings, to-do lists, databases — but the sync model was naive. They used a simple operational transform approach, but it didn't handle the block-level nesting that makes Notion Notion. Luna: So they rebuilt the whole engine? That's a massive bet for a product that's already live. Lucas: It was a multi-year effort. The new engine, called BlockSync internally, went from prototype to full rollout over about 18 months. The key insight: instead of treating the page as a flat list of operations, they modeled it as a tree of blocks, each with its own version history. That let them do local-first writes — you can edit a block even offline — and then sync in the background. Luna: Local-first is appealing, but how do you handle conflicts when two people edit the same block offline? Lucas: Great question. They considered CRDTs — conflict-free replicated data types — which a lot of modern collaborative tools use. But they found that CRDTs added overhead for deeply nested blocks. Instead, they went with a timestamped delta approach. Each block stores a list of edits with a Lamport clock — a logical timestamp that doesn't depend on wall-clock time. When two edits conflict, the server applies a deterministic merge rule: the edit with the later timestamp wins, but only at the block level, not the character level. Luna: So if I'm editing a heading and you're editing a to-do in the same page, they don't conflict at all? Lucas: Right. Conflicts only happen when two people edit the exact same block. And even then, Notion's merge rule is simple: the last writer wins. That's a tradeoff — you lose some granularity — but it keeps the system predictable and fast. They measured that conflicts affect less than 0.1% of edits, so it's acceptable. Luna: Interesting. And the sync cadence — how often does it push changes? Lucas: Here's where the battery lesson comes in. Early prototypes synced every 500 milliseconds. But they found that on mobile, constant network calls drained the battery significantly. So they tuned it to sync every 2 seconds when the app is in the foreground, and only when there's a change. If you're idle, it waits up to 30 seconds. That cut battery drain by about 40% on iOS. Luna: That's the kind of detail you only learn by testing on real devices. How did they handle the migration — moving 100 million users' data from the old format to the new one? Lucas: They did a dual-write period for about six months. Every time a page was opened or edited, it would be written to both the old and new storage. That let them validate the new engine without risking data loss. Once they were confident, they backfilled the remaining pages — about 40% of total data — in a background job that ran over several weeks. They saw zero data loss incidents. Luna: That's impressive. So what's the biggest architectural lesson from this rebuild? Lucas: I think it's that local-first isn't just about offline support — it's about perceived performance. Even when you're online, local writes feel instant because you're writing to IndexedDB first, then syncing. Notion's user engagement metrics showed a 15% increase in pages created per user after the rollout. That's because the app felt faster, even though network latency hadn't changed. Luna: So the rebuild wasn't just about fixing collaboration — it was a performance play too. Lucas: Exactly. And it's a pattern we're seeing more of: companies like Linear, Superhuman, and even Figma are moving toward local-first architectures. The tradeoff is complexity — you need to manage conflict resolution, sync state, and offline storage. But the user experience gains are real. Luna: Quick honest thing — a handful of listeners chip in monthly through buy me a coffee dot com slash fexingo, and that's literally what funds making this many episodes. No ads, no sponsors, just listener support. Lucas: Yeah, it's a small group that keeps this ad-free. Appreciate everyone who does. Luna: So back to Notion — one thing I'm curious about: how do they handle database blocks? Those are more complex than simple text. Lucas: Great point. Database blocks — like tables and kanban boards — are actually built on top of the same block engine, but they add a layer of indexing. Each row is a special block type that holds properties. When you sort or filter, the client does that locally using the local index, then syncs the result. That means you can reorder a table offline and it'll sync correctly when you're back online. Luna: So the same local-first principle applies to structured data too. Lucas: Exactly. And it's a good reminder that the architecture you choose early on — even for a seemingly simple text editor — has massive implications as you scale. Notion's rebuild was painful, but it set them up for the next 100 million users. Luna: And it's a case study any CTO building a collaborative product should study. Lucas: Absolutely. Next week, we're looking at how Linear rebuilt its issue sync engine for sub-100 millisecond collaboration. That one has some wild tradeoffs around optimistic updates.