-
Notifications
You must be signed in to change notification settings - Fork 457
perf(api): wake reservation waiters via pub/sub instead of 20ms polling [ENG-4070] #2729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jakubno
merged 11 commits into
main
from
move-concurrent-connects-to-use-pubsub-same-as-state-change-eng-4070
May 22, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cbd7f37
perf(api): wake reservation waiters via pub/sub instead of 20ms polli…
jakubno 8e1cdab
chore: add todo
jakubno a8d3fa8
chore: clean up
jakubno b8545d7
chore: lint
jakubno 7f13b8b
chore: simplify comments, remove unused function
jakubno 24d2caa
chore: check Redis error
jakubno 8eceefb
chore: add readme for reservation store
jakubno 0b051be
chore: improve comment
jakubno 379f9a6
chore: clean up readme
jakubno abe9362
chore: clean up comments
jakubno 5ce87e5
chore: keep tombstone out of pubsub PR
jakubno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
20 changes: 20 additions & 0 deletions
20
packages/api/internal/sandbox/reservations/redis/README.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Redis Reservation Storage | ||
|
|
||
| This package coordinates sandbox creation reservations across API instances. | ||
|
|
||
| ## Keys | ||
|
|
||
| - Storage index: `sandbox:storage:{teamID}:index` | ||
| - Pending zset: `sandbox:storage:{teamID}:reservations:pending` | ||
| - Result key: `sandbox:storage:{teamID}:reservations:{sandboxID}:result` | ||
| - PubSub routing key: `sandbox:storage:{teamID}:reservations:{sandboxID}:notify` | ||
|
|
||
| ## Flow | ||
|
|
||
| `Reserve` runs a Lua script that atomically removes stale pending entries, checks whether the sandbox already exists or has already pending start, enforces the team limit using `SCARD(storage index) + ZCARD(pending zset)`, deletes any stale result key, and adds the sandbox ID to the pending zset. | ||
|
|
||
| When creation completes, it removes the sandbox from the pending zset, writes a TTL result key containing either the sandbox or the creation error, and publishes the routing key. | ||
|
|
||
| A waiter subscribes to the routing key, probes the result key immediately, then waits for PubSub notifications or the 1 second fallback ticker. PubSub is best-effort; the fallback ticker is required for correctness. | ||
|
|
||
| `Release` is called when the sandbox is removed from storage (`Store.Remove`). It removes the sandbox from the pending zset, deletes the result key, and publishes the routing key. |
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
Oops, something went wrong.
Oops, something went wrong.
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.