Download CV
← all 25 systems

PRJ-002 · platform · 2025 · in daily use

Offline-First Pharmacy Platform

A pharmacy management system that keeps selling when the internet drops, then reconciles every till operation exactly once when it returns.

What can be checked, and what cannot

Client-deployed, so there is no public instance and no public repository

This one runs a working pharmacy day to day and the code belongs to the client, so nothing here is independently inspectable the way the field operations engine is. What is published is the reasoning and the shape of the system. For the mechanisms below under a screen share, ask.

164

Route handlers

sales, returns, stock, suppliers, expiry, reporting

27

Domain models

all syncable through one plugin

11.6k

Application code

lines

In daily use

Status

running a working pharmacy

The problem

A pharmacy cannot stop serving customers because the connection went down, and it cannot tolerate a sale being recorded twice or stock going negative because two tills sold the last box at the same moment. Connectivity in the market this serves is unreliable enough that offline operation is the normal case rather than the exception.

The requirement sounds modest: keep working offline. What it actually means is that the client is authoritative for a period you do not choose, and every operation it queued has to land exactly once when it reconnects.

Every obvious delivery guarantee is the wrong one

At least once

Double-charges. The batch replays after a dropped acknowledgement and the customer pays twice for one box.

At most once

Loses a sale. The till recorded it, the server never did, and the stock count is the only place anyone will notice.

One success branch

An operation can be new, already applied, or in conflict with something that changed while the device was away. Each arm is a genuinely different outcome, and collapsing any two of them produces a bug you will find in a stock count weeks later.

Read, then write stock

Two tills selling the last box both read one remaining and both succeed. Overselling becomes unlikely rather than impossible, which is not the same thing.

Trust the till

An offline client is an untrusted client. Without a field allowlist, a modified device can write a revenue total or a price directly.

The approach

Exactly once, or the shop stops trusting the system

Built the whole platform on the assumption that a till works disconnected and syncs later. Every operation carries a client-generated identifier so a replayed batch is recognised rather than reapplied. Stock decrements are a single guarded increment rather than a read followed by a write, so overselling is structurally impossible instead of merely unlikely.

Offline edits use optimistic concurrency with a field allowlist, so a modified client cannot write a revenue total. A sync plugin makes 27 models syncable without touching 27 files.

Architecture

Offline-first with exactly-once reconciliation. Operations are idempotent by client-generated id, stock is guarded at the database rather than in application logic, and conflicts are tagged for review rather than thrown as errors. A shared sync plugin gives every model the same sync semantics.

A conflict is information: two people did something reasonable and the system cannot rank them without business context. Tagging keeps the batch moving and puts the decision in front of someone who understands the shop.

Node.jsExpressMongoDBSync plugin · 27 models

Four decisions

Each with what it cost

A decision without a stated tradeoff is a preference. These four shaped the reconciliation path, and each one carries a price.

01

A single guarded increment for stock, never read-then-write

Why

The decrement filter carries the availability condition, so the database refuses the operation if stock is insufficient. There is no window between checking and writing.

What it costs

Error handling moves to interpreting a zero-match result rather than reading a friendly precondition first, which is less obvious to read and actually correct under concurrency. Without it, two tills selling the last box both read one remaining and both succeed.

02

Conflicts are tagged, not raised as failures

Why

A conflict during reconciliation is information, not an error. Tagging it keeps the batch moving and puts the decision in front of a human who understands the business context.

What it costs

Someone has to review tagged conflicts, which is a workflow rather than a silent resolution, and that is the honest trade for a system handling money.

03

Field allowlist on offline edits

Why

An offline client is an untrusted client. Without an allowlist, a modified device could write a revenue total or a price directly.

What it costs

New editable fields have to be added to the allowlist deliberately, which is friction that exists precisely so it cannot be skipped.

04

Proportional discount reversal on returns, in two phases

Why

Returning one line of a discounted three-line invoice has to reverse a proportional share of the discount. Computing the whole reversal before applying any of it means a partial failure cannot leave the invoice half-adjusted.

What it costs

More intermediate state than adjusting line by line, in exchange for an operation that either completes or does not.

Known limitations

What this page does not prove

No independent inspection

The code is the client's and the deployment is theirs, so unlike the field operations engine there is no repository to read and no instance to poke. The numbers on this page are mine to state and yours to take on trust, which is exactly the thing this site otherwise tries to avoid.

Conflict review is a workflow, not a resolver

Someone has to review tagged conflicts. That is the honest trade for a system handling money, and it means the reconciliation quality depends on the shop keeping up with its queue.

Not load tested to failure

A pharmacy has a handful of tills, so the reconnect-storm work that the field operations engine went through was never warranted here. There is no published ceiling for this system because I have not found it.