Home   dsa  

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:

2. Design a Parking Lot System

Focus:

3. Design a Library Management System

Focus:

4. Design an Online Bookstore

Focus:

5. Design a Social Media Feed

Focus:

6. Design a Chat Application

Focus:

7. Design an Elevator System

Focus:

8. Design a Cab Booking System

Focus:

9. Design a Hotel Booking System

Focus:

10. Design a Food Delivery System

Focus:


Detailed Example: Design a URL Shortener

Requirements:

  1. Shorten URL: Convert a long URL to a short URL.
  2. Redirect: Given a short URL, redirect to the original long URL.
  3. Scalability: Handle millions of URLs and requests.

Components:

  1. Encoding: Generate a unique short code for each URL.
  2. Database: Store mappings of short codes to long URLs.
  3. Redirection: Service to handle redirecting short URLs to long URLs.

Steps:

  1. 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.
  2. Redirection:

    • Look up the short code in the database.
    • Redirect the user to the corresponding long URL.

Database Schema:

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:

Published on: Jul 09, 2024, 11:50 PM  
 

Comments

Add your comment