Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
description: How Redis is configured, shared in dev, and consumed across Carbon paths: - packages/kv/** - packages/dev/** - packages/env/src/index.ts - packages/dev/docker/docker-compose.dev.yml
Dev shared Redis
Client (@carbon/kv)
- Library is
ioredis(packages/kv/package.json;ioredis-mockfor tests). - Single global singleton in
packages/kv/src/client.ts:new Redis(REDIS_URL, ...)stashed onglobal.__redis(survives HMR / warm lambdas). Options:maxRetriesPerRequest: 3,lazyConnect: true,enableOfflineQueue: true, and aretryStrategythat reconnects forever with capped backoff (min(times * 200, 5000)) so the client auto-recovers when Redis returns — per-command latency is bounded bymaxRetriesPerRequest+ the resilience-layer timeout, not by giving up on reconnection. Throws ifREDIS_URLis unset. - Exported as
{ redis }frompackages/kv/src/index.ts, which also exports theRatelimitclass (a custom ioredis-backed reimplementation of the@upstash/ratelimitAPI using Luaevalscripts — seepackages/kv/src/ratelimit/). - Resilience wrapper (
packages/kv/src/resilient.ts): the singleton is passed throughwithResilience(), a Proxy that makes every command fail soft when Redis is unreachable — reads resolvenull(collections[]), writes resolvenull, andpipeline().exec()resolves[], each with aREDIS_TIMEOUT_MScap. Consumers keep the ordinary ioredis API and need no per-call try/catch; anullread is just a cache miss → read through to the DB.Ratelimit.limit()fails open (success: true) on any Redis error. This is the fix for a Redis outage no longer taking down requests (issue #1076).
Connection config
- One env var:
REDIS_URL— a fullredis://host:port/dbURL. Required + secret (packages/env/src/index.ts,getEnv("REDIS_URL", { isRequired: true, isSecret: true })). There is noREDIS_HOST/PORT/PASSWORDsplit and no in-code default.
Dev: one shared container, per-worktree logical DB
Dev uses a single redis:7-alpine container per host, reused across all
worktrees; each worktree is isolated by a logical DB index (0–15), not its
own container.
- Not a compose service.
packages/dev/docker/docker-compose.dev.yml(the per-worktree Supabase + inngest stack) explicitly documents redis's absence (~line 238). The dev CLI boots redis directly. bootSharedRedis()inpackages/dev/src/services/compose.tsdoesdocker runof containercarbon-redis(volumecarbon-redis-data,-p ${SHARED_REDIS_PORT}:6379,--restart unless-stopped, healthcheckredis-cli ping,redis-server --appendonly yes). Idempotent: reuse running, start stopped, else recreate. ConstantsREDIS_CONTAINER/REDIS_VOLUMEare at the top of that file.SHARED_REDIS_PORT = 6379andREDIS_DB_MAX = 16live inpackages/dev/src/worktree.ts;pickRedisDballocates a free DB index per worktree.- Wired into
crbn upatpackages/dev/src/commands/up.ts("shared redis" task). - The env writer
packages/dev/src/env.tsemitsREDIS_URL=redis://localhost:${SHARED_REDIS_PORT}/${redisDb}— so dev apps connect tolocalhost:6379at the worktree's DB index. crbn reset/crbn removeflush only that worktree's DB viaflushDb(db)→docker exec carbon-redis redis-cli -n <db> FLUSHDB(compose.ts).
Consumers
Two patterns: the shared redis client (caching / TTL state) and the
Ratelimit class (sliding-window). Notable uses:
- Permissions cache — user claims, keyed via
getPermissionCacheKey(userId)(packages/auth/src/services/users.ts; invalidated in the ERP users module, on logout, invite/company creation, and theupdate-permissionsInngest job). - Rate limiting — login/verify (ERP, MES, academy, starter), docs API, shared-customer-file downloads.
- Auth TTL state — WebAuthn passkey challenges, email verification codes
(
packages/auth/src/services/passkey.server.ts,verification.server.ts). - Settings / schema caches (
apps/erp/.../settings.service.ts,shared.service.ts), printer config (packages/printing/src/cache.server.ts), Stripe (packages/stripe/src/stripe.server.ts), Slack EE mapping.
Prod (for contrast)
The self-hosted Swarm stack (contrib/deploying/simple-docker-caddy/docker-compose.prod.yml,
see contrib-deployment-swarm.md) runs a real redis
service (redis:7-alpine, redis-server --appendonly yes, no published host port
— reachable internally at redis:6379); the apps set REDIS_URL=redis://redis:6379.
Managed/cloud deployments override REDIS_URL with an external URL.
Gotchas
getPermissionCacheKeyis duplicated (@carbon/authand the ERP users module). Both produce the same key today but could drift.- An old root
docker-compose.ymlonce held redis and used volumecarbon-shared_redis-data; that path is gone — current volume iscarbon-redis-data. Any old volume is orphaned but harmless (dev redis is cache).