System Design Interview - robbiehume/CS-Notes GitHub Wiki

Overview

Steps

1. Questions

2. API Design

3. Database Design

URL Shortener

Benefits

  • Space saving
  • Link customization
  • Prevent link breaking
  • Improves readability (masking long URLs)
  • Tracking and analytics

Questions

Up front

  • How many URLs: > Billion --> NoSQL; otherwise --> SQL

As you go

  • Do you want user management

Functional Requirements

  • Given a URL, our service should generate a shorter and unique alias of it. This is called a short link. This link should be short enough to be easily copied and pasted into applications.
  • When users access a short link, our service should redirect them to the original link.
  • Users should optionally be able to pick a custom short link for their URL.
  • Links will expire after a standard default timespan. Users should be able to specify the expiration time.

Extended Requirements:

  • Analytics; e.g., how many times a redirection happened?
  • Our service should also be accessible through REST APIs by other services.

Non-Functional Requirements

  • The system should be highly available. This is required because, if our service is down, all the URL redirections will start failing.
  • URL redirection should happen in real-time with minimal latency.
  • Shortened links should not be guessable (not predictable).

API

Database Design

  • Use SQL if your URL shortener is small to medium scale, requires strong consistency, supports custom URLs, or needs complex analytics
  • Use NoSQL if you need to scale to billions of URLs, handle high throughput, and prioritize availability over consistency

Architecture design

  • API Gateway with a Lambda to maintain high availability and scalability, while also limiting costs during down hours