All docs pages
Docs

Stateful objects

Counters, carts, game rooms, rate limits and per-user state that stay correct when many people act at once.

In stackly.json and the CLI it is objects. Its use, live or draft, is counted as object and cache calls; see Live app prices.

objects · optional · needs backend · Durable Objects (SQLite storage) · binding APP_OBJECTS

Small values that must stay correct when many people act at once: counters, locks, seats, votes, carts, per-visitor limits. Each object handles its calls one at a time, so updates are atomic.

Turn it on

"features": ["backend", "objects"]

Use it

import { limit, objects } from "#/lib/objects.server";

const event = objects(`event:${eventId}`);
const taken = await event.increment("seats");            // new value
const won = await event.compareAndSet("lock", null, me);  // true when it was free
await event.put("note", { by: me }, { ttlSeconds: 600 });
const { entries, next } = await event.list({ prefix: "vote:", limit: 50 });

// Per-visitor limit on a form: 5 per 10 minutes.
const { allowed, resetAt } = await limit(`contact:${ip}`, 5, 600);
if (!allowed) return new Response("Too many tries. Try again later.", { status: 429 });

limit() answers { allowed, remaining, resetAt }.

Methods: get, getMany, put, delete, list, increment, compareAndSet, clear.

Limits

Object names 1–128 letters, digits, _, :, . or -. Values are JSON, at most 128 KB each, and can expire.

Don't

Use the database for records you list, search or join. Objects are for small values that need atomic updates.

Locally

stackly dev runs objects locally. The draft and live each have their own.

All app features