What is WatermelonDB for React Native?
Why Interviewers Ask This
This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.
Answer
WatermelonDB is a high-performance, reactive local database for React Native (and web) that uses SQLite under the hood. It's designed for large, complex data sets where performance matters — syncing thousands of records, complex queries, offline-first apps. Why not just AsyncStorage or MMKV? AsyncStorage/MMKV are key-value stores — simple, flat data. WatermelonDB has relational data, indexes, complex queries, and reactive updates. Core concepts: // 1. Define schema: const schema = appSchema({ version: 1, tables: [ tableSchema({ name: "posts", columns: [ { name: "title", type: "string" }, { name: "body", type: "string" }, { name: "user_id", type: "string", isIndexed: true }, { name: "created_at", type: "number" }, ] }), ] }); // 2. Define model: class Post extends Model { static table = "posts"; @field("title") title; @field("body") body; @relation("users", "user_id") user; } // 3. Query with reactivity: const PostsList = withObservables([""], ({ database }) => ({ posts: database.get("posts").query( Q.where("user_id", userId), Q.sortBy("created_at", Q.desc) ).observe(), }))(PostsListUI); // 4. Write in batch (atomic, fast): await database.write(async () => { const post = await database.get("posts").create(post => { post.title = "New Post"; }); });. Sync: WatermelonDB has a built-in sync protocol — sync local changes to your server, pull server changes. Conflict resolution included. Performance: reads are O(1) via indexes; writes are batched; SQLite is far faster than JSON storage for large datasets.
Pro Tip
Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a React Native codebase.