~/upket/writing $ cat tally-offline-sync.md

How Tally stays fast offline

1 min read #tally#engineering

Tally writes every purchase to a local database first. The UI never waits for the network.

The sync queue

Each change becomes a small record in a queue. When the phone is online, the queue drains in order:

data class Change(val id: String, val op: Op, val at: Long)

suspend fun drain(queue: Queue) {
    while (true) {
        val next = queue.peek() ?: break
        api.push(next)
        queue.remove(next.id)
    }
}

Sample post — replace with your own.