Review

Scale live-quiz shards by bumping SHARD_COUNT

PulseArena (live trivia) is crushing Friday-night peaks on 4 Postgres shards. This PR raises SHARD_COUNT to 8 and rewires the FastAPI quiz-state router so sessions hash across the new fleet. Ops says the extra replicas are already provisioned and healthy.

FastAPITier 7shardingroutingmigrationdistributed

Click a line to flag it, pick one or more labels, then submit. If the change looks correct, approve it.

app/routing/quiz_shards.py+2-1
11from fastapi import APIRouter, HTTPException
22from app.db.pool import shard_pools
33
44router = APIRouter(prefix="/v1/quiz", tags=["quiz"])
5-SHARD_COUNT = 4 # must match provisioned quiz_state_* DBs
5+SHARD_COUNT = 8 # scaled out for Friday prime-time load
66
77def shard_for_user(user_id: int) -> int:
88 """Map a player onto a quiz_state shard."""
99 return user_id % SHARD_COUNT
1010
1111@router.get("/sessions/{user_id}/state")
1212async def get_quiz_state(user_id: int):
1313 shard = shard_for_user(user_id)
14+ # New shards 4-7 are empty until traffic naturally fills them — fine for cold start.
1415 pool = shard_pools[shard]
1516 row = await pool.fetchrow(
1617 "SELECT streak, current_q, score FROM quiz_state WHERE user_id = $1",
1718 user_id,
1819 )
1920 if row is None:
2021 raise HTTPException(status_code=404, detail="no active quiz session")
2122 return dict(row)