Build friendship lifecycle backend foundation - #193
Merged
Conversation
Add server-authorized friendship and blocking transitions, privacy-safe REST and realtime contracts, and non-blocking PostgreSQL mirrors. Document the state machine and cover concurrency, replay, blocking, privacy, metrics, and disabled-Postgres behavior.
Gate social routes and realtime delivery behind the disabled-by-default rollout flag. Keep relationship and block tombstones revisioned for fail-closed unblock and reordered PostgreSQL mirrors, and reserve pending-request quota atomically with rollback and stale reconciliation.
Keep in-flight quota reservations counted until their relationship write resolves, and make quota cleanup asynchronous after durable social transitions so mirrors and invalidations are never suppressed by maintenance failures.
Use an atomic, expiring Redis limiter for per-user and per-pair friend request creation so crashes cannot leak durable quota reservations or suppress relationship side effects.
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SOCIAL_FEATURES_ENABLEDRequest-creation limits
This replaces the former pending-request quota/reservation design. Redis atomically limits new requests to 30 per actor per 10 minutes and 3 per normalized pair per 24 hours. A Lua script checks both counters before incrementing either and assigns fixed TTLs, so it works across API processes and crashes leave no durable reservation or cleanup work. Redis failure is fail-closed (
503 request_rate_limit_unavailable); a reached limit is429 request_rate_limitedwith a retry time. Existing cancel/decline pair cooldowns remain.Review hardening
Dependencies and remaining work
Merge order is
#192 / #191 → #185 → this PR; rebase before it is ready. This remains backend foundation only: client invalidation/reconnect reconciliation belongs to #186 and room invitations to #187.Validation
yarn lintyarn test(server: 21 suites / 121 tests; client: 14 suites / 82 tests; scrambles: 1 suite / 22 tests)git diff --checkA fresh-database
prisma migrate deploywas not run locally because the available Lets Cube PostgreSQL container belongs to another active worktree; CI exercises the committed migration against isolated PostgreSQL 17.