Prompt
How do I choose a backend for mobile apps with offline users?
Latest observation
Choosing a backend for a mobile app with offline users is mostly about one question:
What needs to happen when the device is disconnected, and how much conflict can your data tolerate when it reconnects?
Here’s a practical way to decide.
1) Start with your offline requirements
Ask these first:
- Can users read data offline, or must they also create/edit data offline?
- How long can data stay unsynced?
- Is eventual consistency okay, or do you need strong consistency?
- What happens if two devices edit the same record offline?
- Do you need real-time sync, or just background sync?
- Will the app work mostly on flaky mobile networks or truly disconnected environments?
If users only need cached reads, your backend can be much simpler.
If users need full offline editing, syncing, and conflict resolution, you need a backend designed for synchronization, not just storage.
2) Pick an offline strategy
A. Cache-first backend
Best for:
- Mostly read-heavy apps
- Simple offline needs
- Limited or no offline writes
Typical setup:
- REST/GraphQL API
- Local database on device
- Sync only when online
Use when:
- You can tolerate stale data
- Offline writes are rare or unnecessary
Examples:
- News apps
- Content browsers
- Internal dashboards with limited editing
B. Sync-enabled backend
Best for:
- Offline create/edit/delete
- Multiple devices per user
- Conflict handling matters
Typical setup:
- Local persistent store on device
- Change log / operation queue
- Sync engine for push/pull
- Conflict resolution rules
Use when:
- Users may work disconnected for hours or days
- Data must reconcile safely later
Examples:
- Field service apps
- Sales CRM apps
- Delivery/inspection apps
- Notes/task apps with collaboration
C. Event-driven / eventual consistency backend
Best for:
- Complex workflows
- Multi-user collaboration
- Auditability
- Large-scale systems
Typical setup:
- Commands/events instead of direct writes
- Server-side reconciliation
- Background processing
Use when:
- You can model changes as events
- You want robust history and auditing
Examples:
- Logistics systems
- Inventory systems
- Healthcare or regulated workflows
3) Choose the right backend type
Option 1: Traditional API + local SQLite/Realm
Good if you want control and don’t need advanced sync built in.
Pros
- Flexible
- Easier to standardize across platforms
- Works with any backend stack
Cons
- You must build sync, retry, and conflict logic
- More engineering effort
Good backend tech:
- PostgreSQL + API server
- REST or GraphQL
- Local storage: SQLite, Realm, Core Data, Room
Option 2: Backend-as-a-Service with offline support
Good if you want speed and built-in sync.
Examples:
- Firebase / Firestore
- Couchbase Lite + Sync Gateway
- Realm Sync
- Supabase with custom offline layer
- AWS Amplify/DataStore
Pros
- Faster to ship
- Built-in auth, sync, sometimes conflict support
Cons
- Vendor lock-in
- Offline behavior may be opinionated
- Complex sync rules can become limiting
Choose this if:
- You want to reduce backend engineering
- Your data model fits the platform’s sync style
Option 3: Custom sync server
Good if offline behavior is core to the product.
Pros
- Full control over sync semantics
- Custom conflict resolution
- Can optimize for your domain
Cons
- Highest complexity
- More maintenance
- Harder to get right
Choose this if:
- Offline is central to the app
- You need domain-specific reconciliation
- You have a team that can maintain sync infrastructure
4) Think about conflict resolution early
Offline users eventually create conflicts. Decide how you’ll handle them:
- Last write wins: simplest, but can lose data
- Field-level merge: better for structured records
- Server-authoritative: server decides final state
- User-assisted merge: best for important user-generated content
- Operational transforms / CRDTs: best for collaborative editing, but more complex
If your app has forms, field-level merge is often enough.
If users edit the same document collaboratively, look at CRDTs or a collaboration platform.
5) Evaluate backend features that matter for offline apps
Look for:
- Local persistence support
- Incremental sync
- Conflict detection and resolution
- Authentication that works offline or tolerates delayed refresh
- Efficient delta sync
- Retry and idempotency support
- Attachment/file handling
- Schema migration support
- Observability for sync failures
- Multi-platform SDKs
6) Common architecture patterns
Pattern 1: Local-first app
- Device is primary
- Sync is background replication
Best for:
- Offline-first UX
- High resilience
- User control
Pattern 2: Server-first with offline cache
- Server remains source of truth
- Device caches data and queues writes
Best for:
- Simpler business apps
- Moderate offline use
Pattern 3: Domain-specific sync
- Backend exposes commands like “submit inspection,” “close ticket,” “mark delivered”
- Avoids syncing arbitrary records directly
Best for:
- Complex business rules
- Strong audit needs
7) A simple decision guide
Choose a simple API + local DB if:
- Offline is mainly for reading
- Conflict risk is low
- You want maximum flexibility
- You can build sync yourself
Choose a sync platform if:
- Offline writes are important
- You need fast delivery
- You don’t want to engineer sync from scratch
Choose a custom backend if:
- Offline logic is core to your product
- You need custom rules and conflict handling
- You can invest in engineering and testing
8) A good practical default
If you’re unsure, a strong default is:
- Mobile local database: SQLite/Room/Core Data/Realm
- Backend: PostgreSQL
- API: REST or GraphQL
- Sync: custom incremental sync with timestamps/versioning
- Conflict handling: version checks + field-level merge or user resolution
This gives you control without locking you into a niche sync system.
9) Questions to answer before picking
If you answer these, the right backend usually becomes obvious:
- What data must be available offline?
- What actions must work offline?
- How often do conflicts happen?
- Is user data collaborative or mostly personal?
- Do you need attachments/photos offline?
- How important is audit history?
- How many users/devices sync the same data?
- What is your team’s backend expertise?
- Do you need to move fast or optimize deeply?
- Are you okay with vendor lock-in?
10) My rule of thumb
- Simple offline reading: use a standard backend + local cache
- Offline edits with modest complexity: use a sync-capable BaaS
- Serious offline-first product: build custom sync on top of a solid database
- Collaborative editing: consider CRDTs or a specialized collaboration layer
If you want, I can also help you choose a backend based on your app type, team size, and offline requirements.