Bird
Raised Fist0
LLDsystem_design~10 mins

Availability checking in LLD - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a service is available by pinging it.

LLD
def is_service_available(url):
    response = ping(url)
    return response.status_code == [1]
Drag options to blanks, or click blank then click option'
A500
B404
C302
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 which means not found
Using 500 which means server error
2fill in blank
medium

Complete the code to retry checking availability if the first ping fails.

LLD
def check_with_retry(url, retries):
    for _ in range(retries):
        if is_service_available(url):
            return True
    return [1]
Drag options to blanks, or click blank then click option'
ANone
BTrue
CFalse
DException
Attempts:
3 left
💡 Hint
Common Mistakes
Returning True even if service is down
Returning None which is ambiguous
3fill in blank
hard

Fix the error in the code to handle timeout exceptions during availability check.

LLD
def safe_check(url):
    try:
        return is_service_available(url)
    except [1]:
        return False
Drag options to blanks, or click blank then click option'
ATimeoutError
BValueError
CKeyError
DIndexError
Attempts:
3 left
💡 Hint
Common Mistakes
Catching ValueError which is unrelated
Catching KeyError which is for dicts
4fill in blank
hard

Fill both blanks to implement exponential backoff in retry logic.

LLD
def retry_with_backoff(url, retries):
    delay = 1
    for _ in range(retries):
        if is_service_available(url):
            return True
        time.sleep([1])
        delay = delay [2] 2
    return False
Drag options to blanks, or click blank then click option'
Adelay
Bdelay + 2
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 2 instead of multiplying
Using a fixed delay without change
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps service names to their availability status.

LLD
services_status = [1]: safe_check([2]) for [3] in services_list}
Drag options to blanks, or click blank then click option'
A{service
Bservice
Cservice_name
Dservice}
Attempts:
3 left
💡 Hint
Common Mistakes
Missing curly brace
Using wrong variable names

Practice

(1/5)
1. What is the main purpose of availability checking in system design?
easy
A. To create backups of system data
B. To increase the speed of data processing
C. To encrypt user data for security
D. To determine if a resource is free or ready to use

Solution

  1. Step 1: Understand the concept of availability checking

    Availability checking is about verifying if a resource like a room, item, or slot is free to be used or booked.
  2. Step 2: Identify the main goal

    The main goal is to know if the resource is ready or free, not about speed, security, or backups.
  3. Final Answer:

    To determine if a resource is free or ready to use -> Option D
  4. Quick Check:

    Availability checking = resource readiness [OK]
Hint: Availability checking means resource is free or not [OK]
Common Mistakes:
  • Confusing availability with performance optimization
  • Mixing availability with security features
  • Thinking availability means data backup
2. Which of the following code snippets correctly checks if a room is available given a list of booked rooms booked_rooms = [101, 102, 103] and a requested room requested_room = 104?
easy
A. if requested_room in booked_rooms: print('Available')
B. if requested_room == booked_rooms: print('Available')
C. if requested_room not in booked_rooms: print('Available')
D. if requested_room > booked_rooms: print('Available')

Solution

  1. Step 1: Understand the list and requested room

    booked_rooms contains rooms already taken: 101, 102, 103. requested_room is 104.
  2. Step 2: Check correct condition for availability

    Room is available if requested_room is NOT in booked_rooms. So, 'if requested_room not in booked_rooms' is correct.
  3. Final Answer:

    if requested_room not in booked_rooms: print('Available') -> Option C
  4. Quick Check:

    Not in booked_rooms means available [OK]
Hint: Check 'not in' to confirm availability [OK]
Common Mistakes:
  • Using 'in' instead of 'not in' to check availability
  • Comparing equality of a number to a list
  • Using greater than operator on list
3. Given the following code, what will be the output?
booked_slots = {"9AM": True, "10AM": False}
requested_slot = "10AM"
if not booked_slots.get(requested_slot, False):
    print("Slot Available")
else:
    print("Slot Booked")
medium
A. Slot Available
B. Slot Booked
C. KeyError
D. No output

Solution

  1. Step 1: Understand the dictionary and requested slot

    booked_slots maps times to True (booked) or False (free). "10AM" is False, meaning free.
  2. Step 2: Evaluate the condition

    booked_slots.get("10AM", False) returns False. 'not False' is True, so it prints "Slot Available".
  3. Final Answer:

    Slot Available -> Option A
  4. Quick Check:

    False means free, so output is Slot Available [OK]
Hint: False means free slot, so print available [OK]
Common Mistakes:
  • Assuming True means available instead of booked
  • Expecting KeyError when key exists
  • Ignoring default value in get()
4. Identify the bug in the following availability check code:
def is_available(stock, requested):
    if requested > stock:
        return True
    else:
        return False

print(is_available(5, 10))
medium
A. The function should return False when requested is greater than stock
B. The function is correct and returns True
C. The condition should be 'requested <= stock' to return True
D. The function should compare 'stock > requested' instead

Solution

  1. Step 1: Analyze the condition logic

    Current code returns True if requested > stock, meaning more requested than available stock.
  2. Step 2: Correct logic for availability

    Availability means stock should be enough or more than requested. So, if requested > stock, return False.
  3. Final Answer:

    The function should return False when requested is greater than stock -> Option A
  4. Quick Check:

    Requested > stock means not available [OK]
Hint: Availability means stock >= requested, else False [OK]
Common Mistakes:
  • Returning True when requested exceeds stock
  • Confusing greater than with less than
  • Not testing with example values
5. You are designing an availability checking system for a hotel booking platform. Which approach best ensures high availability and scalability when checking room availability in real-time?
hard
A. Use a centralized database with locking to check and update availability synchronously
B. Cache availability data in memory with periodic sync to the database and use optimistic concurrency
C. Check availability by scanning all booking records on every request without caching
D. Allow double booking and resolve conflicts manually later

Solution

  1. Step 1: Understand requirements for high availability and scalability

    System must respond quickly and handle many requests without blocking.
  2. Step 2: Evaluate options for real-time availability checking

    Cache availability data in memory with periodic sync to the database and use optimistic concurrency uses caching and optimistic concurrency, reducing database load and avoiding locks, improving scalability and availability.
  3. Final Answer:

    Cache availability data in memory with periodic sync to the database and use optimistic concurrency -> Option B
  4. Quick Check:

    Caching + optimistic concurrency = scalable availability [OK]
Hint: Cache data and use optimistic concurrency for scalable availability [OK]
Common Mistakes:
  • Using locking causing bottlenecks
  • Scanning all records causing slow response
  • Allowing double booking causing user issues