# Zero Sync Engine Architecture and ZQL Mechanics
> An exhaustive technical guide to Rocicorp's Zero sync engine, zero-cache Postgres WAL replication, zero-client IndexedDB execution, and ZQL query streaming.
Author: Aaron Boodman
Published: 2026-06-15 | Modified: 2026-07-25
---
Zero, developed by Rocicorp and released in 1.0 form in June 2026, is a general-purpose, query-driven synchronization engine for web applications[1]. Founded by Aaron Boodman, Zero combines client-side IndexedDB caching (zero-client) with a cloud middleware replica (zero-cache) that monitors PostgreSQL Write-Ahead Logs (WAL)[1]. By executing client queries using Zero Query Language (ZQL) through Incremental View Maintenance (IVM), Zero achieves zero-millisecond read response times while preserving server-side authorization authority[2].
## Systemic Architectural Components
Unlike legacy sync frameworks that force applications to download an entire database up-front or manually manage REST/GraphQL caches, Zero introduces query-driven background streaming[1]. The architecture comprises three primary layers:
1. **PostgreSQL Database**: The authoritative central source of truth storing persistent application records[1].
2. **zero-cache Middleware**: A stateful cloud node that uses Postgres logical replication (`wal_level = logical`) to maintain a local SQLite read replica. It validates incoming client ZQL query parameters against server authorization rules[1].
3. **zero-client Engine**: A JavaScript runtime library compiled into the client web app. It manages a client-side IndexedDB store, executing queries locally in zero milliseconds while maintaining an active WebSocket connection to `zero-cache`[1].
```
[ Browser (zero-client) ] <-- 0ms ZQL Read --> [ Local IndexedDB ]
^ |
|--- Incremental Row Streaming (WS) -------|
v
[ Cloud (zero-cache) ] <-- Logical Replication -- [ Postgres WAL ]
```
## ZQL Execution and Optimistic Mutations
When an application invokes a query via `useQuery(zqlQuery)`, the query executes against local memory first, returning matching local records immediately within the next frame[1]. In parallel, `zero-client` sends the ZQL subscription parameters to `zero-cache`, which validates authorization, executes the query against its SQLite replica, and streams missing or updated rows over WebSockets[1].
```typescript
// ZQL Query Example in Client Runtime
const zqlQuery = z.issue
.where('status', '=', 'open')
.related('assignee')
.limit(50);
const [issues] = useQuery(zqlQuery); // 0ms execution from local cache
```
Write operations execute locally using optimistic mutations, sending mutation intents to the backend server where business rules reconcile changes before broadcasting authoritative state back down to all subscribed clients[2].
## Frequently Asked Questions
### Q: What is Rocicorp Zero?
Zero, tagged 1.0 stable in June 2026 by Rocicorp, is a query-driven synchronization engine for web apps that connects client-side IndexedDB caching (zero-client) with a Postgres WAL replication middleware (zero-cache).
### Q: How does zero-cache sync with PostgreSQL?
zero-cache connects to Postgres using logical replication (wal_level = logical), listening to Write-Ahead Log changes to update an internal SQLite replica and stream row diffs to subscribed clients over WebSockets.
### Q: What is ZQL (Zero Query Language)?
ZQL is a declarative TypeScript query API that executes instantly in local memory while automatically subscribing the client to real-time server diffs validated against backend authorization rules.