Bird
0
0
LLDsystem_design~3 mins

Why Scheduling algorithm (SCAN, LOOK) in LLD? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your elevator or disk could magically know the best path to serve everyone quickly?

The Scenario

Imagine you are managing a busy elevator in a tall building. Without a smart plan, the elevator moves randomly, going up and down without order, making people wait long and wasting energy.

The Problem

Manually deciding which floor to visit next can be slow and confusing. It causes delays, wastes time, and frustrates users because the elevator might zigzag inefficiently, just like a disk head moving back and forth without a plan.

The Solution

Scheduling algorithms like SCAN and LOOK organize the elevator's movement by sweeping in one direction, serving requests in order, then reversing. This reduces wait times and travel distance, making the system smooth and efficient.

Before vs After
Before
while requests:
  next_floor = random.choice(requests)
  move_to(next_floor)
  requests.remove(next_floor)
After
direction = 'up'
while requests:
  floors_in_direction = get_floors_in_direction(current_floor, direction)
  serve_floors_in_order(floors_in_direction)
  direction = reverse(direction)
What It Enables

It enables fast, predictable, and fair servicing of requests, improving overall system performance and user satisfaction.

Real Life Example

Disk scheduling in operating systems uses SCAN and LOOK to decide the order of reading or writing data, minimizing the disk arm movement and speeding up access.

Key Takeaways

Manual scheduling causes inefficiency and delays.

SCAN and LOOK algorithms organize requests by direction to optimize movement.

This leads to faster, fairer, and more predictable service.