Stop building "dumb" clients. TopGun turns your client into a replica. Zero-latency reads/writes, offline-first reliability, and real-time sync powered by CRDTs and Merkle Trees.
import { TopGun } from '@topgunbuild/client';
// 1. Initialize Local-First DB
const db = new TopGun({
sync: 'wss://api.topgun.build',
persist: 'indexeddb'
});
// 2. Zero-Latency Write (Optimistic)
await db.todos.set({
id: 'task-1',
text: 'Ship v2',
status: 'pending'
}); // Resolves in ~0.5msExperience offline-first sync in action. Drag drones on the local map, toggle offline mode, and watch how conflicts are resolved automatically.
~16ms in productionDelays slowed for visual clarity
| ID | COORD | STATUS | HLC |
|---|---|---|---|
| D-01 | [20, 30] | PATROL | 1000 |
| D-02 | [60, 70] | IDLE | 1000 |
| D-03 | [80, 20] | RTB | 1000 |
TopGun Architecture:
The Server acts as source of truth using Hybrid Logical Clocks (HLC) to order events. When offline, local changes are queued. Upon reconnect, Merkle Trees detect diffs, and Last-Write-Wins resolves conflicts automatically.
TRY THIS: Go offline, then reconnect. Watch how TopGun resolves conflicting coordinates based on HLC timestamps!
TopGun bridges the gap between scalable In-Memory Data Grids and Offline-First Client Databases.
Reads and writes happen locally against an in-memory CRDT. The UI updates in <16ms (one frame) using Optimistic UI patterns by default. No spinners, no waiting.
The network is optional. Data is automatically persisted to IndexedDB (Browser) or SQLite (Mobile/Desktop) and synced when connectivity returns.
Efficient bandwidth usage. We only exchange the modified leaves of the Merkle Tree, drastically reducing data transfer costs compared to REST/GraphQL.
A server-authoritative cluster that coordinates HLC (Hybrid Logical Clocks) and persists to standard databases like PostgreSQL or Mongo. You own your data.
Automatic convergence via CRDTs. No manual conflict resolution code required for standard operations.
Pessimistic locking with fencing tokens prevents split-brain scenarios. Essential for critical operations like payments or inventory updates.
Push-based architecture via WebSockets ensures all active clients receive updates instantly.
TopGun inverts the traditional model. The client is the primary source of truth for the UI, while the server ensures eventual consistency and persistence.
The only solution that combines the speed of an In-Memory Data Grid with robust Offline-First capabilities.
| Feature | TopGun | ElectricSQL | Firebase | RxDB |
|---|---|---|---|---|
| Primary Model | Local-First IMDG | Postgres Sync | Cloud Doc DB | Local-First DB |
| Offline Support | First-Class | Good | Good | Excellent |
| Latency | ~0ms (In-Memory) | ~5-10ms (SQLite) | Network Dependent | ~5-10ms (IndexedDB) |
| Backend Control | Self-Hosted Cluster | Sync Service | Proprietary | CouchDB / Custom |
| Consistency | HLC + CRDT | Rich CRDTs | LWW (Server) | Revision Trees |
| Distributed Locks | Fencing Tokens | Not Supported | Not Supported | Not Supported |
| License | Open Source | Open Source | Proprietary | Open Source |