Building Apps That Work Without a Connection

    Learn how to build offline-first mobile apps: local databases, sync, conflict resolution, background jobs and testing, with real tools and trade-offs.

    Omer Hassan

    Founder & CEO

    9 min read
    Share
    On this page

    A site supervisor walks into a concrete basement to log an inspection. The app spins, then shows "No internet connection." Twenty minutes of notes and photos are gone. By lunch, the team is back on paper forms, and your app is the thing they complain about.

    Connectivity fails more often than office-based teams expect: basements, warehouses, rural job sites, hospital corridors, planes, crowded events. If your users work in those places, an app that needs a signal for every tap will lose their trust fast.

    This guide explains how to build offline-first mobile apps: what the term means, when you need it, the architecture that makes it work, how to handle sync conflicts, and the mistakes that cause lost data.

    What Offline-First Actually Means

    An offline-first app treats the local database on the device as the main source of truth. Every read and write happens locally first, so the app is fast and works with no signal. A sync engine then moves changes to and from the server whenever a connection is available.

    That's different from an "offline-capable" app, which works online by default and caches a few screens. Offline-capable is fine for reading news. It breaks down when people need to create or edit data without a signal.

    Do You Need an Offline-First App?

    Not every app does. Offline-first adds real engineering work, so match the effort to how your users actually work.

    App typeOffline needWhy
    Field service, construction, inspectionsEssentialWork happens where signal is weak or absent
    Healthcare at the point of careHighClinicians can't wait for a page to load
    Retail point of sale and inventoryHighA dropped connection can't stop a sale
    Travel, events, delivery driversHighUsers move between coverage areas
    Note-taking and productivityMediumUsers expect edits to never disappear
    Banking and paymentsLow to mediumView data offline, but most actions need the server
    Social feeds and streamingLowCache content; real-time features need a connection

    If your users would ever lose work because of a dropped connection, plan for offline-first from the start. Adding it to an app that was built online-only usually means rebuilding the data layer.

    The Core Architecture

    Most reliable offline-first apps share four building blocks:

    1. A local database that stores everything the user needs to see and change.
    2. An outbox (sync queue) that records every change made on the device, in order.
    3. A sync engine that sends queued changes to the server and pulls down changes made elsewhere.
    4. A server API built for sync, with change tracking, timestamps or version numbers, and safe retries.

    The user interface reads only from the local database. When the user saves something, the app writes it locally, updates the screen instantly and adds a record to the outbox. The sync engine handles the network in the background.

    Here's a simplified version of the outbox pattern in TypeScript:

    typescript
    // Save locally first, then queue the change for sync
    async function saveInspection(inspection: Inspection) {
      await db.transaction(async (tx) => {
        await tx.inspections.upsert({ ...inspection, updatedAt: Date.now() });
        await tx.outbox.insert({
          id: crypto.randomUUID(),      // idempotency key for safe retries
          entity: 'inspection',
          entityId: inspection.id,
          operation: 'upsert',
          payload: inspection,
          createdAt: Date.now(),
        });
      });
    }
    
    // Runs when the device is online, and on a background schedule
    async function flushOutbox() {
      const pending = await db.outbox.orderBy('createdAt').limit(50);
      for (const change of pending) {
        const res = await api.post('/sync', change, {
          headers: { 'Idempotency-Key': change.id },
        });
        if (res.ok) await db.outbox.delete(change.id);
        else break; // keep order; retry later with backoff
      }
    }

    The idempotency key matters. Mobile networks often drop the response after the server has already saved the change. Without the key, a retry can create duplicates.

    Choosing a Local Database

    The right choice depends on your framework, data shape and how much sync logic you want to own.

    OptionBest forNotes
    SQLite (via Room on Android, GRDB or SwiftData/Core Data on iOS)Most native appsProven, fast, full control; you build sync yourself
    SQLite in React Native or Flutter (e.g. op-sqlite, Drift)Cross-platform appsSame SQLite strengths with a cross-platform API
    WatermelonDBLarge React Native datasetsBuilt for lazy loading and sync, with your own backend
    PowerSync or ElectricSQLApps on Postgres that want managed syncSyncs a subset of server data into local SQLite
    Couchbase LiteEnterprise apps needing built-in syncMature sync with conflict handling; licensing cost for some editions
    Firebase Firestore offline persistenceApps already on FirebaseEasy to start; less control over conflicts and query limits
    Realm (Atlas Device SDK)Existing Realm appsMongoDB ended Atlas Device Sync in September 2025; the on-device database remains open source

    If you're starting fresh with a relational backend, SQLite plus a clear sync API is the safest long-term choice. It keeps you independent of any one vendor's sync service.

    Handling Sync Conflicts

    A conflict happens when the same record changes on two devices, or on a device and the server, before they sync. You need a rule for which change wins, decided per type of data, not left to chance.

    Common strategies:

    • Last write wins: the most recent change replaces the older one. Simple, but it can silently overwrite someone's work. Fine for low-stakes fields like a display name.
    • Field-level merge: compare changes field by field, so one person's edit to "status" and another's edit to "notes" both survive.
    • Server authority: the server decides, using business rules. Best for stock levels, balances and anything with money attached.
    • Append-only records: instead of editing a record, add new entries (like "added 5 units"). Totals are calculated from the history, so nothing is overwritten.
    • CRDTs (conflict-free replicated data types): data structures designed to merge automatically. Powerful for collaborative text and lists, but more complex to build and reason about.
    • Ask the user: show both versions and let a person choose. Use sparingly, only where a wrong automatic choice would be costly.

    Whatever you choose, use server-assigned version numbers or timestamps rather than trusting device clocks, which are often wrong.

    Background Sync on iOS and Android

    Users expect their changes to reach the server even if they close the app. Both platforms allow this, within limits:

    • Android: use WorkManager with a network constraint, so sync runs when a connection returns, even after the app is closed or the phone restarts.
    • iOS: use BGTaskScheduler for background refresh and processing. iOS decides when tasks run based on battery, usage and network, so never rely on an exact schedule. Sync on app launch and when the app returns to the foreground as well.

    Keep background work small and resumable. Sync in batches, and save progress after each batch so an interrupted sync picks up where it left off.

    UX Patterns That Build Trust

    Offline-first isn't only a data problem. Users need to understand what's happening:

    • Show a clear sync status: "All changes saved," "3 changes waiting to sync," or "Last synced 2 minutes ago."
    • Update the screen instantly when users save, without waiting for the server.
    • Mark items that haven't synced yet with a small icon, so users don't assume a colleague can see them.
    • Handle large files like photos separately, with their own upload queue and progress indicator.
    • Never show a blank screen when offline. Show the last known data with a gentle offline banner.

    Security for Data Stored on the Device

    Offline data lives on a phone that can be lost or stolen. Protect it:

    • Encrypt the local database, for example with SQLCipher or the platform's file protection classes.
    • Store tokens and keys in the iOS Keychain or Android Keystore, never in plain files or shared preferences.
    • Sync only the data each user actually needs, not the whole database.
    • Support remote wipe of local data when an account is disabled.

    These steps matter even more in regulated industries, which we cover in our post on mobile app security for fintech and healthcare.

    How to Test an Offline-First App

    Most offline bugs only show up in messy, real-world conditions. Build these into your test plan:

    • Airplane mode in the middle of saving, uploading and syncing
    • Slow and unstable networks, using Network Link Conditioner on iOS or emulator network throttling on Android
    • Two devices editing the same record offline, then reconnecting
    • Killing the app during sync, then reopening it
    • Very large local datasets on older, low-storage devices
    • App updates that change the local database schema (migrations)

    When those pass, our guide to passing App Store review the first time covers the last step before launch.

    What Offline-First Adds to Cost and Timeline

    Offline-first typically adds work in three places: the local data layer, the sync API on the back end, and testing. For a focused app, that might add a few weeks. For apps with many data types and complex conflict rules, it can be a significant share of the build.

    The cheapest time to decide is before you build. Retrofitting offline support into an online-only app usually costs more than designing for it from day one.

    Common Mistakes to Avoid

    • Calling the API directly from screens, so nothing works without a signal
    • Trusting device clocks to decide which change is newer
    • Retrying without idempotency keys, creating duplicate records
    • Syncing the entire database to every device
    • Storing sensitive offline data unencrypted
    • Testing only on fast office Wi-Fi

    Frequently Asked Questions

    What is an offline-first app?

    It's an app that saves and reads data on the device first and syncs with the server when a connection is available. Users can keep working with no signal, and their changes upload automatically later.

    Can a React Native or Flutter app work offline?

    Yes. Both can use SQLite-based local databases and background sync. The architecture (local database, outbox, sync engine) is the same as for native apps.

    How do offline apps handle conflicts?

    They use a defined rule per type of data, such as last write wins, field-level merging, server-side business rules or append-only records. The right rule depends on how costly a wrong merge would be.

    Is offline-first more expensive to build?

    It adds work to the data layer, back end and testing, so yes, it costs more than an online-only app. For teams that work in low-signal places, it's usually far cheaper than lost data and abandoned apps.

    Build for the Basement, Not the Office

    The best offline-first apps feel boring in the best way: users tap save, the app responds instantly, and their work shows up on the server when the signal returns. Getting there takes a local-first data layer, a sync API designed for retries and conflicts, and testing in the conditions your users actually face.

    TechKnoc builds mobile apps and the back-end sync APIs behind them, including field tools like the Linx site tracker for construction teams. Our React Native developers build the same offline mode into iOS and Android apps from one codebase. To see where site reporting fits in a contractor's wider workflow, read about automating construction site reporting. If your users work where the signal doesn't, book a free consultation and talk to the engineer who'll build it.

    Found this useful? Share it with your team.

    Written by

    Omer Hassan

    Founder & CEO, TechKnoc

    Omer Hassan is the Founder & CEO of TechKnoc, started in 2022 to make production-grade AI and custom software accessible to growing businesses. Omer writes practical guides on topics like app development cost, CI/CD for manual deploys, AWS vs Azure vs Google Cloud and infrastructure as code, drawing on 40+ delivered projects and the work behind TechKnoc's custom software and DevOps and cloud services.

    Keep reading

    All articles