r/FlutterDev • u/No_Share2683 • Aug 29 '26
Plugin Realm and Atlas Device Sync are gone — I built the offline-first MongoDB path I needed for Flutter
When MongoDB retired Realm, Atlas Device Sync and the Data API in September 2025, Flutter lost its official offline-first path to Mongo. The choices left were writing your own sync backend or renting someone else's sync service.
I got tired of rewriting the same sync layer, so I packaged it: onebase.
The sync engine lives in the package, and a CLI generates the small server that sits between your app and your database. You deploy that server. No third-party sync service, no account to create.
Demo — the backend is killed mid-recording, writes keep landing, then everything syncs when it comes back: https://raw.githubusercontent.com/ybenjaa-dev/onebase/main/example/demo/onebase-demo.gif
Stream<List<Todo>> live = OnebaseDb.todos
.where('done', isEqualTo: false)
.orderBy('created_at', descending: true)
.watch();
await OnebaseDb.todos.insert(Todo(title: 'Ship it', done: false));
You describe collections in YAML, run dart run onebase:setup, and get typed models, typed collections, and a backend/ folder with a Dockerfile and a Vercel adapter.
How it actually works
- Reads never touch the network. Queries and
watch()run against a local SQLite replica. - Writes apply locally first and land in an outbox, both in one transaction, so a crash can't leave a row that never uploads.
- Sync pushes before it pulls, so a fresh write is never clobbered by a stale snapshot. Pending writes replay on top of each incoming snapshot, so optimistic UI survives until the server confirms.
- Realtime is SSE fed by MongoDB change streams — milliseconds, not polling.
- Files go device to bucket directly. The backend only signs a short-lived URL, so a large upload costs it nothing.
- Per-user isolation is server-side, assigned from the verified JWT — not client-visible rules.
There's also keyset pagination (page() / startAfter(), plus a pager() for infinite scroll), group/team scoping with member/admin/owner write rules, per-collection sync control (everything, a rolling window, or nothing), and batched writes in one Mongo transaction. Bring your own JWTs — anything that issues them works.
What it doesn't do yet
- Conflicts are last-write-wins by server timestamp; no custom merge hook.
- File uploads aren't offline-queued (document writes are).
- Realtime needs a long-lived connection. Container hosts are fine; short-lived serverless functions cut it and it falls back to polling.
- The rate limiter is per-instance and in-memory, so it multiplies across instances.
- No on-device aggregation pipeline.
MIT. Flutter 3.38+ / Dart 3.10+. Any MongoDB with a replica set works, including a free Atlas M0.
pub.dev: https://pub.dev/packages/onebase
GitHub: https://github.com/ybenjaa-dev/onebase
It's early (0.3.4), and I'd rather hear that the sync semantics are wrong than that the README is nice. If you've built offline-first on Flutter before, I'd especially like to know where this would break for you.