perf(api): batch MGET calls in TeamItems to avoid giant Redis commands - #3571
Open
AdaAibaby wants to merge 1 commit into
Open
perf(api): batch MGET calls in TeamItems to avoid giant Redis commands#3571AdaAibaby wants to merge 1 commit into
AdaAibaby wants to merge 1 commit into
Conversation
Previously TeamItems issued a single MGET for every sandbox ID returned
by SMEMBERS, which could send thousands of keys in one command, blocking
the Redis event loop and spiking response-buffer memory.
Split the fan-out into sandboxScanBatchSize (256) key chunks, consistent
with the scan path already doing the same thing in forEachTeamSandboxBatch.
All keys share the {teamID} hash tag so each batch still lands on the same
cluster slot regardless of chunk boundaries.
Add TestTeamItems_BatchesLargeTeams to exercise the chunked path with
513 sandboxes (2×256+1, forcing 3 MGET batches).
AdaAibaby
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
August 14, 2026 10:06
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.
Problem
TeamItemsissues a singleMGETfor every sandbox ID returned bySMEMBERS.For teams with many sandboxes (we've observed 9 000+ IDs in a single team index),
this means one command can carry thousands of keys — blocking the Redis event loop
and spiking per-connection response-buffer memory.
Fix
Split the
MGETfan-out intosandboxScanBatchSize(256) key chunks, consistentwith the scan path already doing the same in
forEachTeamSandboxBatch.All team sandbox keys share the
{teamID}hash tag, so every batch lands onthe same cluster slot regardless of where the chunk boundaries fall.
Changes
operations.go— loop oversandboxIDsin 256-key slices, callingfetchSandboxBatchper sliceteam_items_test.go— addTestTeamItems_BatchesLargeTeams: creates 513 sandboxes (2×256+1) and verifies all are returned, exercising all three MGET batchesTesting
New test exercises the chunked path. Existing tests cover state filtering, stale
index entries, corrupt records, empty teams, and team isolation — all still pass.
(Tests use testcontainers-go; they require Docker which isn't available in the local
environment but run in CI.)