Mid From PDF MNC Coding C# MNC Coding Interview

Design a rate limiter?

Design a rate limiter

What interviewers test

  • Concurrency
  • Thread safety
  • System design

Token bucket (simple)

public class RateLimiter
{
private readonly int _limit;
private int _count;
private DateTime _windowStart = DateTime.UtcNow;
private readonly object _lock = new();
public RateLimiter(int limit)
{
_limit = limit;
}
public bool Allow()
{

lock (_lock)

{
if ((DateTime.UtcNow - _windowStart).TotalSeconds >= 1)
{
_count = 0;
_windowStart = DateTime.UtcNow;
}
if (_count < _limit)
{

_count++;

return true;
}
return false;
}
}
}

Used in

  • APIs
  • Login attempts
  • OTP systems

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details