--- introduction.mdx --- Zero is a new kind of sync engine powered by queries. Rather than syncing entire tables to the client, or using static rules to carefully specify what to sync, you just write queries directly in your client code. Queries can access the entire backend database. Zero caches the data for queries locally on the device, and reuses that data automatically to answer future queries whenever possible. For typical applications, the result is that almost all queries are answered locally, instantly. It feels like you have access to the entire backend database directly from the client in memory. Occasionally, when you do a more specific query, Zero falls back to the server. But this happens automatically without any extra work required. Zero is made possible by a custom streaming query engine we built called [ZQL](reading-data), which uses [Incremental View Maintenance](https://www.vldb.org/pvldb/vol16/p1601-budiu.pdf) on both client and server to efficiently keep large, complex queries up to date. ## Status Zero is in alpha. There are still some rough edges, and to run it, you need to [deploy it yourself](deployment) to AWS or similar. Even so, Zero is already quite fun to work with. We are using it ourselves to build our very own [Linear-style bug tracker](https://bugs.rocicorp.dev/). We find that Zero is already much more productive than alternatives, even having to occasionally work around a missing feature. If you are building a new web app that needs to be fast and reactive, and can do the deployment yourself, it's a great time to get started with Zero. We're working toward a [beta release and full production readiness](roadmap) this year. --- quickstart.mdx --- ## Prerequisites - Docker - Node 20+ This quickstart uses React, but we also have it available for SolidJS. See: [SolidJS](/docs/solidjs). ## Run In one terminal, install and start the database: ```bash git clone https://github.com/rocicorp/hello-zero.git cd hello-zero npm install npm run dev:db-up ```
Not using npm? Zero's server component depends on `@rocicorp/zero-sqlite3`, which contains a binary that requires running a postinstall script. Most alternative package managers (non-npm) disable these scripts by default for security reasons. Here's how to enable installation for common alternatives: ### pnpm For [pnpm](https://pnpm.io/), either: - Run `pnpm approve-builds` to approve all build scripts, or - Add the specific dependency to your `package.json`: ```json "pnpm": { "onlyBuiltDependencies": [ "@rocicorp/zero-sqlite3" ] } ``` ### Bun For [Bun](https://bun.sh/), add the dependency to your trusted dependencies list: ```json "trustedDependencies": [ "@rocicorp/zero-sqlite3" ], ```
In a second terminal, start `zero-cache`: ```bash cd hello-zero npm run dev:zero-cache ``` In a final terminal, start the UI: ```bash cd hello-zero npm run dev:ui ``` ## Quick Overview `hello-zero` is a demo app that allows querying over a small dataset of fake messages between early Zero users. Here are some things to try: - Press the **Add Messages** button to add messages to the UI. Any logged-in or anonymous users are allowed to add messages. - Press the **Remove Messages** button to remove messages. Only logged-in users are allowed to remove messages. You can **hold shift** to bypass the UI warning and see that write access control is being enforced server-side – the UI flickers as the optimistic write happens instantly and is then reverted by the server. Press **login** to login as a random user, then the remove button will work. - Open two different browsers and see how fast sync propagates changes. - Add a filter using the **From** and **Contains** controls. Notice that filters are fully dynamic and synced. - Edit a message by pressing the **pencil icon**. You can only edit messages from the user you’re logged in as. As before you can attempt to bypass by holding shift. - Check out the SQL schema for this database in `seed.sql`. - Login to the database with `psql postgresql://user:password@127.0.0.1:5430/postgres` (or any other pg viewer) and delete or alter a row. Observe that it deletes from UI automatically. ## Detailed Walkthrough