Session storage migration
Plan for moving session storage from Redis to Postgres: KPIs, diagram, rollout options, diff and a decision form.
- ~947 tokens
- 34 statements
- passes
austere-axi check
OpenUI Lang source
root = Stack([intro, kpis, flow, options, openQuestion, change, files, decide], "column", "l")
intro = Card([CardHeader("Session storage migration", "Move sessions from Redis to Postgres"), introText])
introText = MarkDownRenderer("Sessions live only in Redis and are lost on failover — last month that logged out **~38k users** twice.
**Goal:** durable sessions with no forced logout, and no extra p99 latency on the auth path.
- Keep the `SessionStore` interface unchanged
- Cut over behind the `sessions_pg` flag")
kpis = OverviewCardBlock([kpiUsers, kpiP99, kpiCost])
kpiUsers = OverviewCardItem("users", Text("text", "Forced logouts / mo"), MetricIndicatorInline("38,214", "last 30 days", {direction: "up", value: 12}))
kpiP99 = OverviewCardItem("p99", Text("text", "Auth p99"), MetricIndicatorInline("41 ms", "target ≤ 45 ms"))
kpiCost = OverviewCardItem("cost", Text("text", "Extra storage"), MetricIndicatorInline("$140/mo", "Postgres, 3 replicas"))
flow = Card([CardHeader("Request path after the change"), flowDiagram])
flowDiagram = Architecture([client, edge, api, pg, redis], [toEdge, toApi, toPg, toRedis], [platform])
client = Node("Client", "external", "browser / mobile")
edge = Node("Edge worker", "cloud", "Cloudflare")
api = Node("API", "backend", "Node :8080")
pg = Node("Postgres", "database", "sessions table", "new")
redis = Node("Redis", "database", "read-through cache")
toEdge = Edge(client, edge, "HTTPS", "emphasis")
toApi = Edge(edge, api)
toPg = Edge(api, pg, "SQL")
toRedis = Edge(api, redis, "during rollout", "dashed")
platform = Group("Platform VPC", [api, pg, redis])
options = Card([CardHeader("Rollout options"), optionTable, latencyChart])
optionTable = Table([Col("Option", ["Big bang", "Dual-write"]), Col("Effort", ["2 days", "5 days"]), Col("Downtime", ["~10 min", "none"]), Col("Risk", [riskHigh, riskLow])])
riskHigh = Tag("high", null, "sm", "danger")
riskLow = Tag("low", null, "sm", "success")
latencyChart = BarChart(["p50", "p90", "p99"], [Series("Redis", [4, 11, 38]), Series("Postgres", [6, 15, 44])], "grouped", "Percentile", "ms")
openQuestion = Callout("warning", "Open question", "Keep Redis as a read-through cache after cutover, or drop it entirely?")
change = Card([CardHeader("Core change", "src/session/store.ts"), storePatch])
storePatch = Diff("diff --git a/src/session/store.ts b/src/session/store.ts
--- a/src/session/store.ts
+++ b/src/session/store.ts
@@ -12,7 +12,11 @@ export class SessionStore {
async get(id: string) {
- return this.redis.get(key(id));
+ const cached = await this.redis.get(key(id));
+ if (cached) return cached;
+ const row = await this.pg.sessions.find(id);
+ if (row) await this.redis.set(key(id), row, { ex: TTL });
+ return row;
}")
files = Card([CardHeader("Files touched"), changedFiles])
changedFiles = FileTree(["M src/session/store.ts # read-through to Postgres", "A src/session/pg-store.ts", "A migrations/0042_sessions.sql # table + expiry index", "M src/config.ts # SESSIONS_PG flag", "M test/session.test.ts"])
decide = Card([CardHeader("Your call"), decideForm])
decideForm = Form("rollout", decideButtons, [strategyField, notesField])
strategyField = FormControl("Rollout", RadioGroup("strategy", [RadioItem("Big bang", "One deploy, short maintenance window", "bigbang"), RadioItem("Dual-write", "Two weeks writing to both stores", "dualwrite")]))
notesField = FormControl("Notes", TextArea("notes", "Anything to change?", 3))
decideButtons = Buttons([Button("Send decision", @ToAssistant("Decision: rollout strategy"), "primary"), Button("Explain the risk column")])