A point-of-sale system has one requirement that overrides everything else: when the internet drops, selling must not stop. Not degrade. Not queue a spinner. The cashier taps a product, the total appears, the receipt prints, and none of that is allowed to depend on a server being reachable.
That requirement is what shaped the whole architecture, and it is why the interesting decisions were not about UI.
The shape
- One Next.js codebase rendered into two shells: a Tauri window on desktop, a Capacitor webview on Android. Same routes, same components, same business rules.
- A local database on each device, embedded, holding the catalog, prices, and the order history it created.
- A server with Postgres, reachable when the network is, as the long-term source of truth and the place multiple devices converge.
- Domain-driven structure: orders, catalog, payments, and inventory are separate modules with their own models and their own events, not one shared blob of types.
The single codebase is the decision that paid off fastest. Every feature written once worked in the shop on a tablet and at the back office on a desktop. The two shells differ in maybe a few hundred lines: printing, file access, device capabilities. Everything else is shared.
What "offline-first" really means
It means the local database is the source of truth for the device, not a cache. The app reads from it, writes to it, and the sync is a background process that reconciles later. Get this backwards, and every screen has to handle "the server is down" as an error case, which means every screen has to be written twice.
It also means the local database has to be a real database. An in-memory store with a JSON dump to disk looks fine in a demo and falls apart the first time the app is killed mid-write. Local data was stored encrypted at field level, so a lost tablet did not mean a lost customer list.
The problems that actually cost time
Conflicts are not theoretical. Two devices selling the last unit of the same item, both offline, both right from their own point of view. You need a rule before you need code: which field wins, what a "sale" event means when it arrives late, and what the cashier sees when the server disagrees with the device. Event-sourced order records helped here, because the sale is a fact that happened, not a row to be overwritten.
Migrations run on devices you cannot reach. A schema change has to run on a tablet in a shop with a database full of real orders, with no DBA and no rollback. Every migration has to be idempotent and forward-only, and you have to accept that some devices will skip three versions at once.
The clock lies. Device clocks drift, timezones get changed, and an order created "before" an earlier one breaks every assumption in your sync. Server-assigned sequence numbers for ordering, device time only as a display value.
Bundle size and startup. A Next.js app in a webview has a cold start the browser never shows you. The desktop shell hides it better than Android does. Route-level code splitting and keeping the catalog out of the initial bundle made the difference between an app that opens and an app that feels broken.
Printing. Every shop has a different thermal printer, and no two behave the same. This was the largest single block of shell-specific code, and it is the kind of thing that never appears in an architecture diagram.
What I would do differently
- Write the sync contract first, before the UI. The shape of an order event, its identity, and its ordering rule is the spine of the whole system, and changing it after there is data on devices is painful.
- Test with the network off from day one. Not at the end. A team that develops online and tests offline at the end finds a hundred assumptions in a week.
- Keep the domain layer free of the shell. Business rules that import Tauri or Capacitor APIs are rules that cannot be tested in a browser and cannot be reused when the next shell appears.
The honest summary
Offline-first is not a feature you add. It is a constraint that reorganises the architecture: a real local database, a sync model designed before the screens, and migrations treated as a production concern from the first release. The payoff is a system that keeps selling when the network does not, which for a shop is the entire point.
Top comments (0)