instant README

The project's README from github.com/instantdb/instant. As one markdown file: README.md.

Shows the Instant logo

stars

Get Started · Examples · Try the Demo · Docs · Discord

Instant is the best backend for AI-coded apps. You get auth, permissions, storage, presence, and streams — everything you need to ship apps your users will love.

You write relational queries in the shape of the data you want and Instant handles all the data fetching, permission checking, and offline caching. When you change data, optimistic updates and rollbacks are handled for you as well. Plus, every query is multiplayer by default.

We also support ephemeral updates, like cursors, or who's online. Currently we have SDKs for Javascript, React, and React Native.

How does it look? Here's a barebones chat app in about 12 lines:

// ༼ つ ◕_◕ ༽つ Real-time Chat
// ----------------------------------
// * Updates instantly
// * Multiplayer
// * Works offline

import { init, id } from "@instantdb/react";

const db = init({ 
  appId: process.env.NEXT_PUBLIC_APP_ID,
});

function Chat() {
  // 1. Read
  const { isLoading, error, data } = db.useQuery({
    messages: {},
  });

  // 2. Write
  const addMessage = (message) => {
    db.transact(db.tx.messages[id()].update(message));
  };

  // 3. Render!
  return <UI data={data} onAdd={addMessage} />;
}

Want to see for yourself? try a demo in your browser.

Motivation

Writing modern apps is full of schleps. Most of the time you start with the server: stand up databases, caches, ORMs, and endpoints. Then you write client-side code: stores, selectors, mutators. Finally you paint a screen. If you add multiplayer you need to think about stateful servers, and if you support offline mode, you need to think about IndexedDB and transaction queues.

To make things worse, whenever you add a new feature, you go through the same song and dance over and over again: add models, write endpoints, stores, selectors, and finally the UI.

Could it be better?

In 2021, we realized that most of the schleps we face as UI engineers are actually database problems in disguise. (We got into greater detail in this essay)

Shows how Instant compresses schleps

If you had a database on the client, you wouldn't need to think about stores, selectors, endpoints, or local caches: just write queries. If these queries were multiplayer by default, you wouldn't have to worry about stateful servers. And if your database supported rollback, you'd get optimistic updates for free.

So we built Instant. Instant gives you a database you can use in the client, so you can focus on what’s important: building a great UX for your users, and doing it quickly.

Architectural Overview

Here's how Instant works at a high level:

Shows how Instant compresses schleps

Under the hood, we store all user data as triples in one big Postgres database. A multi-tenant setup lets us offer a free tier that never pauses.

A sync server written in Clojure talks to Postgres. We wrote a query engine that understands datalog and InstaQL, a relational language that looks a lot like GraphQL:

// give me all users, their posts and comments
{
  users: {
    posts: {
      comments: {
      }
    }
  }
}

Taking inspiration from Asana’s WorldStore and Figma’s LiveGraph, we tail postgres’ WAL to detect novelty and invalidate relevant queries.

For the frontend, we wrote a client-side triple store. The SDK handles persisting a cache of recent queries to IndexedDB on web, and AsyncStorage in React Native.

All data goes through a permission system powered by Google's CEL library.

Getting Started

The easiest way to get started with Instant is by signing up on instantdb.com. You can create a functional app in 5 minutes or less.

If you have any questions, you can jump in on our discord.

Contributing

You can start by joining our discord and introducing yourself. Even if you don't contribute code, we always love feedback.

If you want to make changes, start by reading the client and server READMEs. There you'll find instructions to start Instant locally.

instant (instantdb/instant)

Searching Database…

10.6K ·GitHub
这是什么?Instant 是一种后端即服务(BaaS),为客户端应用提供默认支持多人协作的关系型数据库,并内置身份验证、权限控制、文件存储、在线状态和实时数据流,因此你无需编写传统的后端。
这是我需要安装的库,还是托管服务?两者兼有:你使用小型客户端 SDK(JS、React、React Native)直接在应用中编写 InstaQL 查询,而实际数据存放在 Instant 托管的多租户 Postgres 数据库和同步服务器中,你无需运行任何服务器端代码。
我该如何开始使用 Instant?前往 instantdb.com 注册即可。大约 5 分钟内就能让一个可用的应用运行起来,无需自己配置数据库或后端。
我需要先自己搭建数据库或接口吗?不需要。Instant 取代了常见的“数据库加 ORM 加接口”组合;你只需在客户端编写 InstaQL 查询,Instant 会为你处理数据获取、权限检查和缓存。
我能自己部署 Instant,而不用 instantdb.com 吗?README 中记录的使用方式是托管服务。自行部署仅作为贡献者的开发环境说明(阅读客户端和服务器端的 README,以便在本地运行 Instant),并不是成熟的一键部署方案。
我的应用数据到底存放在哪里?你的数据以三元组(triples)的形式存储在 Instant 运营的一个大型多租户 Postgres 数据库中,该数据库同时也支撑其常驻免费套餐。
什么是 InstaQL?InstaQL 是 Instant 的关系型查询语言,设计思路与 GraphQL 相似,用于在客户端精确描述你所需数据的结构。
Instant 能在离线状态下配合乐观更新工作吗?可以。客户端 SDK 会缓存最近的查询结果(网页端使用 IndexedDB,React Native 端使用 AsyncStorage),并在你修改数据时自动处理乐观更新和回滚。
在线状态和临时更新有什么用?它们用于实现轻量的多人协作功能,例如实时光标或“谁在线”提示,与 Instant 中持久化数据的查询相互独立。
团队为什么要做一个可在客户端使用的数据库,而不是普通后端?团队发现,大多数应用开发中的麻烦(状态存储、选择器、接口)本质上都是数据库问题,因此 Instant 将一个默认支持多人协作、可回滚的数据库直接放在客户端中,而不是让你编写服务器端代码。
Creator
instantdb
Size
130.4 MB
Stars
10.6K
Updated
CommitSep 28
Age
2y
Commits · 90 Days