← AT&T Interview Insights

AT&T·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Technical phone screen where they gave me a rate limiter implementation problem. Pretty focused coding session, no fluff, just build the thing and explain your choices.

Questions Asked (1)

Q1

Implement a token bucket rate limiter class with a method that accepts a token count and a timeout. The bucket starts full at 1000 tokens, refills continuously at 10 tokens per second up to the max, and each call consumes tokens. If there aren't enough tokens, the method should wait up to the given timeout before giving up and returning false.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the token bucket concept but blanked a bit on the continuous refill part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then design the TokenBucket class with thread-safe state and a refill mechanism based on elapsed time. Implement the tryConsume method using a condition variable to wait for tokens up to the timeout, and discuss trade-offs like fairness and precision.

Pro tip: Use a monotonic clock (e.g., System.nanoTime()) for refill calculations to avoid issues with system clock adjustments, and mention that you'd consider using a lock-free approach or a scheduled refill for high-throughput scenarios.

1. Clarify Requirements and Edge Cases

Ask about thread safety, timeout semantics (e.g., wait up to timeout, then return false), and whether tokens can be consumed partially. Confirm that the bucket starts full and refills continuously.

2. Design the Class Structure

Define fields: maxTokens (1000), refillRate (10 tokens/sec), currentTokens, lastRefillTimestamp, and a lock/condition. Outline methods: refill() to add tokens based on elapsed time, and tryConsume(tokens, timeout) to attempt consumption with waiting.

3. Implement Refill Logic

Calculate tokens to add as (elapsedTime * refillRate), cap at maxTokens, and update lastRefillTimestamp. Ensure refill is called before any consumption attempt.

4. Implement tryConsume with Timeout

Acquire lock, refill, and if enough tokens, consume and return true. Otherwise, wait on condition with remaining timeout, looping until tokens available or timeout expires. Return false if timeout reached.

5. Discuss Trade-offs and Optimizations

Mention fairness (FIFO vs. not), precision of refill, and alternatives like scheduled refills or lock-free atomic operations. Consider how to handle large token requests and potential starvation.

Key Points to Mention

  • Thread safety using locks and condition variables to handle concurrent calls.
  • Continuous refill calculation based on elapsed time, not periodic updates.
  • Timeout handling with wait/notify and remaining time calculation.
  • Use of monotonic clock to avoid system time changes affecting refill.
  • Trade-offs: fairness, precision, and performance under high contention.
  • Edge cases: requesting more tokens than max, zero timeout, and negative inputs.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.