top 10 system design questions asked in fresher interview
System design questions for fresher interviews are usually simpler than those asked of experienced candidates but still aim to assess an understanding of basic principles and the ability to think about scalable systems. Here are the top 10 system design questions often asked in fresher interviews, along with brief explanations of what to focus on:
1. Design a URL Shortener
Focus:
- Generating a unique short URL for a given long URL.
- Redirection from the short URL to the original URL.
- Handling collisions and ensuring scalability.
2. Design a Parking Lot System
Focus:
- Different types of parking spots (e.g., for bikes, cars, trucks).
- Entry and exit points.
- Handling parking fees and availability.
3. Design a Library Management System
Focus:
- Handling books, users, and transactions.
- Borrowing and returning books.
- Search functionality for books.
4. Design an Online Bookstore
Focus:
- Managing a catalog of books.
- User accounts, shopping cart, and checkout process.
- Handling inventory and orders.
5. Design a Social Media Feed
Focus:
- Posting updates.
- Displaying a feed of posts from friends/followed accounts.
- Handling likes, comments, and sharing.
6. Design a Chat Application
Focus:
- Sending and receiving messages.
- Handling real-time updates.
- Managing user presence (online/offline status).
7. Design an Elevator System
Focus:
- Managing requests from different floors.
- Handling multiple elevators.
- Optimizing for efficiency and minimizing wait time.
8. Design a Cab Booking System
Focus:
- Matching riders with drivers.
- Handling real-time location updates.
- Managing bookings and payments.
9. Design a Hotel Booking System
Focus:
- Searching for available rooms.
- Booking and cancelling reservations.
- Managing room inventory and customer accounts.
10. Design a Food Delivery System
Focus:
- Listing restaurants and their menus.
- Handling orders and payments.
- Real-time tracking of delivery.
Detailed Example: Design a URL Shortener
Requirements:
- Shorten URL: Convert a long URL to a short URL.
- Redirect: Given a short URL, redirect to the original long URL.
- Scalability: Handle millions of URLs and requests.
Components:
- Encoding: Generate a unique short code for each URL.
- Database: Store mappings of short codes to long URLs.
- Redirection: Service to handle redirecting short URLs to long URLs.
Steps:
-
Shortening:
- Generate a short code (e.g., base62 encoding).
- Check for collisions in the database.
- Store the mapping of the short code to the long URL.
-
Redirection:
- Look up the short code in the database.
- Redirect the user to the corresponding long URL.
Database Schema:
- URLs table:
id
(primary key)long_url
(text)short_code
(varchar)
Example Code (Pseudo-code):
class URLShortener:
def __init__(self):
self.url_map = {}
self.counter = 0
def shorten_url(self, long_url):
short_code = self._generate_short_code()
self.url_map[short_code] = long_url
return f"short.url/{short_code}"
def _generate_short_code(self):
self.counter += 1
return base62_encode(self.counter)
def redirect(self, short_code):
return self.url_map.get(short_code, "URL not found")
# Helper function for base62 encoding
def base62_encode(number):
characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
base = len(characters)
result = []
while number:
result.append(characters[number % base])
number //= base
return ''.join(result[::-1])
Considerations:
- Collision Handling: Use a retry mechanism or a more complex encoding algorithm.
- Scaling: Distribute the storage across multiple databases or use a distributed cache like Redis.
- Analytics: Track the number of clicks on each short URL for analytics purposes.
Published on: Jul 09, 2024, 11:50 PM