Server to Process Fair Number of Functions

How would you design a server that has to process a fair number of functions of a requests in a second?
What if you are not aware of how many requests you will be getting?
What if requests has different priorities?

💡Strategies for Solving This Problem

Load Balancing and Request Handling

Got this at Meta in 2024. It's about designing scalable systems that handle variable load. Tests understanding of queuing, load balancing, and priority systems.

The Problem

Design a server that processes thousands of function requests per second. Challenges:

  • Unknown request rate
  • Different priorities
  • Need fairness
  • Can't block

Approach 1: Simple Queue

Single FIFO queue. Process requests as they come. Simple but:

  • No priorities
  • High-priority requests wait behind low-priority
  • Doesn't scale well

Approach 2: Priority Queue

Use heap or priority queue. High-priority requests first. Better, but:

  • Starvation: low-priority may never execute
  • Not truly "fair"

Approach 3: Multiple Queues + Round Robin

Separate queue per priority level. Use weighted round-robin to process:

  • 60% time on high priority
  • 30% on medium
  • 10% on low

Prevents starvation while maintaining priorities.

Approach 4: Thread Pool with Work Stealing

Multiple worker threads. Each has local queue. If idle, "steal" work from others. Good for:

  • Load balancing
  • Utilizing all cores
  • Handling variable load

Key Components

Rate limiting: Prevent overwhelming server

Back pressure: Reject requests when overloaded

Monitoring: Track queue sizes, latencies

Autoscaling: Add workers when load increases

At Meta

They wanted to see if I understood the tradeoffs. Started with simple queue, they asked about priorities. Then about fairness and starvation. Finally discussed scaling and monitoring.

Scroll to Top