WhoBuilt

Next-generation React databases

Sep 14, 2018· 27 min· 18K views·Watch on YouTube

Speaker

Radosław Pietruszewski, a software engineer at Nozbe, presents WatermelonDB, an offline-first data persistence framework for React and React Native, at a Callstack tech talk.

When an app needs a database

Pietruszewski distinguishes online content apps, which may need only a cache, from offline-first apps that must let people create and manage data without a connection. Examples include note-taking, task management, and money management apps. These apps can accumulate many records, show the same information in different views, and sync across devices or users.

Why loading everything slows apps down

Keeping app data in Redux or MobX and loading it all into JavaScript can work for smaller apps, but Pietruszewski says it does not scale well. A team account in Nozbe might contain thousands or tens of thousands of projects, tasks, and comments, making startup slow. He argues that mobile performance should be judged by interaction time, including launch time, rather than database throughput alone.

Lazy loading with reactive updates

WatermelonDB loads only the records needed for the current screen and lets native code handle database work. Pietruszewski also describes it as observable: when a task changes, related task lists and project counters can update automatically. The framework uses indexing, caching, batching, and native threading to reduce unnecessary work.

Platforms, sync, and a performance demo

On React Native, WatermelonDB uses SQLite; on the web, it uses LokiJS in a web worker. It is not a sync engine, but it tracks records added, changed, or deleted so developers can connect a separate sync system. In a demo, the app launched in about 200 milliseconds on an iPhone X with 10,000 records, and in about 800 milliseconds on a Moto G5.

Models and queries in practice

Pietruszewski shows how developers define tables, fields, and relationships, then expose them through JavaScript models. A post can belong to a blog and have many comments, while a blog-level query can find nasty comments across its posts. He points viewers to the WatermelonDB GitHub repository for installation, documentation, and demo code.

Takeaways

  • For offline-first apps, a cache may not support the data creation and editing users need without a connection.
  • Loading an entire growing dataset into JavaScript at startup can make mobile apps feel slow.
  • Fetch only the records needed for the current view, and let database queries handle filtering.
  • Observable data can keep related lists and counters in sync without manually coordinating every component.
  • WatermelonDB provides sync tracking primitives, but teams need to connect a separate sync engine.

Mentioned in this talk

Search inside this talk

What was claimed 12

Related talks