PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Snapchat

Implement a Leaky Bucket Limiter

Last updated: Apr 2, 2026

Quick Overview

This question evaluates understanding of rate-limiting algorithms (leaky bucket), concurrent programming, time-based state management, and thread-safe API design.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Implement a Leaky Bucket Limiter

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Design and implement an in-memory leaky-bucket rate limiter. A limiter is configured with: - `capacity`: the maximum amount of queued load the bucket can hold - `leak_rate`: how many units drain from the bucket per second Each incoming request contributes 1 unit to the bucket. When a request arrives: 1. First, reduce the current bucket level based on how much time has elapsed since the last update. 2. If adding the new request would keep the bucket level at or below `capacity`, accept the request and update the bucket level. 3. Otherwise, reject the request. Implement a thread-safe API such as `allow_request()` for use in a multithreaded server. Follow-up discussion: - How would you make the implementation safe under high concurrency? - What synchronization strategy would you use, and what are the trade-offs? - How would you handle time precision, bursty traffic, and clock-related edge cases? - How would you scale this design if many application instances must share the same rate limit?

Quick Answer: This question evaluates understanding of rate-limiting algorithms (leaky bucket), concurrent programming, time-based state management, and thread-safe API design.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Feb 23, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0
Loading...

Design and implement an in-memory leaky-bucket rate limiter.

A limiter is configured with:

  • capacity : the maximum amount of queued load the bucket can hold
  • leak_rate : how many units drain from the bucket per second

Each incoming request contributes 1 unit to the bucket. When a request arrives:

  1. First, reduce the current bucket level based on how much time has elapsed since the last update.
  2. If adding the new request would keep the bucket level at or below capacity , accept the request and update the bucket level.
  3. Otherwise, reject the request.

Implement a thread-safe API such as allow_request() for use in a multithreaded server.

Follow-up discussion:

  • How would you make the implementation safe under high concurrency?
  • What synchronization strategy would you use, and what are the trade-offs?
  • How would you handle time precision, bursty traffic, and clock-related edge cases?
  • How would you scale this design if many application instances must share the same rate limit?

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.