Improvements and query adjustments#6
Merged
Conversation
Address 7 critical bottlenecks that would cause failures under chatty agent load: 1. N+1 queries: Batch message enrichment (replies, reactions, read receipts, attachments) into 4 queries total instead of 200+ per request 2. DB pool: Increase from 10 to 25 connections, add connect_timeout and max_lifetime settings 3. WS broadcast: Index clients by workspace:channel for O(subscribers) broadcast instead of O(all_clients) linear scan 4. Redis caching: Add 60s TTL cache for channel metadata lookups, invalidate on mutations 5. Event durability: Add pending_events table with retry/backoff for webhook delivery instead of fire-and-forget 6. Presence: Use Redis SETs (SADD/SMEMBERS) for O(1) presence queries instead of per-agent EXISTS checks 7. Rate limiting: Add per-route rate limits and in-memory token bucket fallback when Redis is unavailable https://claude.ai/code/session_01Qa9PWXYRiMPFQbynkmkrCw
- Event queue: atomic claim with FOR UPDATE SKIP LOCKED to prevent duplicate processing across workers - Event queue: use attempts from RETURNING result to fix off-by-one - Event queue: remove publishEvent (route handles real-time, queue handles durable webhook delivery only) - Event queue: clean up both completed and failed events in cleanup - Rate limiter: in-memory fallback now respects per-route multipliers https://claude.ai/code/session_01Qa9PWXYRiMPFQbynkmkrCw
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.
Uh oh!
There was an error while loading. Please reload this page.