Skip to content

Replace Redis with PostgreSQL - #3016

Open
howardchung wants to merge 3 commits into
masterfrom
replace-redis-with-postgres
Open

howardchung wants to merge 3 commits into
masterfrom
replace-redis-with-postgres

Conversation

@howardchung

Copy link
Copy Markdown
Member

Summary

Replaces Redis (ioredis) with PostgreSQL-backed UNLOGGED tables and native LISTEN/NOTIFY pub/sub.

Changes

  • Schema (sql/create_tables.sql): Added 5 UNLOGGED tables (kv_store, kv_hash, kv_zset, kv_set, kv_list) with TTL indexes (expires_at), compatible with PostgreSQL 9.5+.
  • PostgreSQL KV client (svc/store/redis.ts): Replaced ioredis with a PostgreSQL-backed client supporting strings/buffers, EX/NX atomic locks, incr/incrby, hashes, sorted sets, sets (with FOR UPDATE SKIP LOCKED spop), lists, distinct counts, multi().exec(), publish via pg_notify, TTLs, and cleanupExpiredKv().
  • Pub/Sub & Health (svc/web.ts): Switched /logs{/:jobId} SSE streaming to PostgreSQL LISTEN/NOTIFY and /healthz to check PostgreSQL (SELECT 1).
  • Cleanup & Monitoring (svc/cleanup.ts, svc/monitor.ts): Added periodic cleanupExpiredKv() to cleanup and removed redisUsage.
  • Deps & Infra: Uninstalled ioredis, removed REDIS_URL and Redis container/scripts from config.ts, docker-compose.yml, dev/gce.sh, README.md, and deleted dev/redis.sh.

Verification

  • npm run typecheck passes cleanly.
  • Verified all KV operations (strings, binary buffers, EX/NX, incrby, hashes, multi().exec(), sorted sets, sets/spop, lists/ltrim, distinct counts, LISTEN/NOTIFY, expiration cleanup, flushdb) live against PostgreSQL 9.5.

@builder-247

Copy link
Copy Markdown
Member

Out of personal curiosity, what motivated this?

@howardchung

Copy link
Copy Markdown
Member Author

Just an experiment to see if we can reduce the number of databases we need to run. I don't know if I will actually merge this because unlogged tables are truncated on crash so there could be random resets

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants