System Design Application Based Questions Flashcards
Two methods of shortening URLs
Hashing and Counter Based
How would you use Hashing to shorten URL ? What about Collision ?
Use a hash function like SHA-256 on the original URL and encode the hash using base62 (using characters 0-9, a-z, A-Z) to get a shorter version. To handle collisions (different URLs hashing to the same value), you can append an increasing sequence number to URLs before hashing.
How would you use the Counter Based Approach to shorten URLs ? collision issues ?
Use an auto-incrementing counter (globally or per user). The counter value can be encoded using base62 to form a short URL. This method ensures uniqueness without collisions but is predictable and might need additional handling to scale horizontally.
Which DBs can be used for consistency and structured data ?
SQL databases like PostgreSQL or MySQL are good for strong consistency and structured data.
Which DBs can be used for high availability and sharding ?
NoSQL databases like DynamoDB or Cassandra offer high availability and are designed to scale out by using sharding.