PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Implement a thread-safe rate limiter

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to design and implement a thread-safe per-user API rate limiter, focusing on concurrency control, synchronization techniques, and time-based request accounting in the Coding & Algorithms domain.

  • medium
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Implement a thread-safe rate limiter

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Design and implement a per-user API rate limiter. Requirements: - Method: `boolean allow(String userId, long nowMillis)` returns whether the request is allowed at time `nowMillis`. - Policy: allow at most **N** requests per **W** milliseconds per user. - Choose any standard algorithm (e.g., fixed window, sliding window, token bucket). Follow-ups: - How do you make it safe under concurrency (multiple threads calling `allow` for the same `userId`)? - Discuss tradeoffs between using locks vs lock-free/low-lock approaches (e.g., `ConcurrentHashMap`, atomics) and performance implications.

Quick Answer: This question evaluates a candidate's ability to design and implement a thread-safe per-user API rate limiter, focusing on concurrency control, synchronization techniques, and time-based request accounting in the Coding & Algorithms domain.

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
Jan 26, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
3
0

Design and implement a per-user API rate limiter.

Requirements:

  • Method: boolean allow(String userId, long nowMillis) returns whether the request is allowed at time nowMillis .
  • Policy: allow at most N requests per W milliseconds per user.
  • Choose any standard algorithm (e.g., fixed window, sliding window, token bucket).

Follow-ups:

  • How do you make it safe under concurrency (multiple threads calling allow for the same userId )?
  • Discuss tradeoffs between using locks vs lock-free/low-lock approaches (e.g., ConcurrentHashMap , atomics) and performance implications.

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.