Introduction
RxDB (Reactive Database) is an offline-first, NoSQL client-side database for JavaScript runtimes. It stores data locally, reacts to changes with RxJS observables, and optionally syncs with a remote backend. This makes it well-suited for progressive web apps, Electron apps, and mobile apps built with React Native.
What RxDB Does
- Stores JSON documents locally with schema validation via JSON Schema
- Emits reactive change streams so UI components update automatically
- Replicates bidirectionally with CouchDB, REST endpoints, GraphQL, or WebRTC peers
- Supports IndexedDB, SQLite, OPFS, and in-memory storage backends
- Encrypts fields at the document level for client-side data protection
Architecture Overview
RxDB sits between your application code and a pluggable storage layer. The RxStorage interface abstracts the underlying engine so the same database API works across browsers, Node.js, React Native, and Electron. Changes are tracked via an internal event stream built on RxJS, and a replication protocol syncs deltas with a remote server.
Self-Hosting & Configuration
- Install via npm or yarn and import the desired storage plugin
- No server is required for local-only usage
- For replication, point the sync plugin at a CouchDB-compatible endpoint or a custom REST/GraphQL server
- Schemas are defined in JSON Schema draft and enforced at write time
- Key-encryption and compression plugins can be enabled per collection
Key Features
- RxJS-based reactivity makes real-time UI binding straightforward
- Multiple storage backends allow the same code to run in any JS environment
- Conflict handling strategies ship built-in for multi-device sync
- Schema migration helpers upgrade documents across versions
- Leader election plugin coordinates background tasks in multi-tab apps
Comparison with Similar Tools
- PouchDB — CouchDB-only sync and no reactive API; RxDB adds observables and flexible storage
- Dexie.js — thin IndexedDB wrapper without built-in replication; RxDB offers full sync and reactivity
- WatermelonDB — React Native focused; RxDB targets every JS runtime
- Firestore — cloud-managed; RxDB keeps data on the client and lets you choose the backend
FAQ
Q: Does RxDB work in Node.js? A: Yes. Use the Node.js storage plugins (SQLite or filesystem-based) for server-side usage.
Q: How large can a local database grow? A: Practical limits depend on the storage backend. IndexedDB in browsers typically allows hundreds of megabytes; SQLite backends handle much more.
Q: Is RxDB free for commercial use? A: The core is Apache-2.0. Some premium plugins require a license for production use.
Q: Can I use RxDB without RxJS in my project? A: RxJS is a core dependency. However, you only interact with observables for change streams; basic CRUD does not require RxJS expertise.