Loading…
Session revocations at scale
CanvaLlew Vallis
Summary
Canva gateways check in-memory session revocations on every request, but pulling over a million revocations from MySQL during deployments created severe database stampedes. To eliminate this bottleneck, the team transitioned to storing a twelve-hour sliding window of revocations in Amazon S3 partitioned into 30-minute chunks. Each revocation is packed into a 16-byte binary structure within a sorted flat array, allowing gateways to query records via direct binary search without object deserialization. Asynchronous workers batch updates into S3 using ZooKeeper leader election and conditional PUT requests for optimistic concurrency control. This architecture reduced the in-memory cache footprint by 87.5% and allowed the team to reduce their MySQL database to just two read replicas.
Context
Hundreds of gateway pods querying over a million session revocation records directly from MySQL on startup created a database stampede during deployments. In addition, storing twelve hours of revocations as individual Java objects imposed a large in-memory cache footprint.
Approach / What changed
Canva partitioned a twelve-hour sliding window of revocations into 30-minute chunks stored in Amazon S3 as sorted, 16-byte packed binary arrays. Asynchronous workers use ZooKeeper leader election and conditional PUT requests to batch updates into S3, while gateway pods stream these chunks on startup and update them via conditional GET requests, searching records directly using binary search.
Takeaways
- Packing each revocation into a 16-byte binary structure within a sorted flat array reduced in-memory cache size by 87.5% compared to Java heap objects and enabled direct binary search lookups.
- Splitting the twelve-hour sliding window into 30-minute chunks in S3 allowed gateways to stream binary data directly on startup and fetch updates using S3 conditional GET requests.
- Asynchronous worker processes used conditional PUT requests for optimistic concurrency control alongside ZooKeeper leader election to prevent lost updates when modifying S3 chunks.
Related reading
Canva ·
Image replacement in Canva designs using reverse image search
Canva needed an automated way to replace media in design templates, such as when third-party licensing partnerships expire across more than 150 million images. Existing recommendation engines, perceptual hashing, and text metadata searches failed to capture visual similarity hierarchies or ensure replacement relevance. To build a reverse image search system, engineers evaluated embedding models including CLIP, ViTMAE, DreamSim, CaiT, and DINOv2 alongside an external vector database supporting metadata filtering. Evaluation on sample datasets identified DINOv2 as the best model for preserving subjects, background context, and color tones in photos. Integrated into the Template Assistant as a human-in-the-loop tool, the automated suggestions increased image replacement speeds by 4.5 times during initial pilot testing.
Sam JacobsNetflix ·
How and Why Netflix Built a Real-Time Distributed Graph: Part 3 — Querying the graph with gRPC…