Design Part 2

Short URL

Short URL

original long url: data tracking and analysis

original short url

Short URL

In Twitter, Weibo, you have charactor limit. Also normal URL will contain some invalid ASCII code that you cannot put into the content.

 

So a lot of company has its own Short URL

Example: http://t.cn/RGKGR3T

Short URL

Design A System that can generate this Short URL

  • The user input an URL, the server returns a short one
  • Other user click this short URL, it will redirect to the real URL
  • If the URL has not been used (no one clicks for 72 hours, configurable), it will be removed

How to generate a short URL

UUID

MD5

 

Are these too long? Could we find a better way?

Think about the requirement

one URL could be used released after some day

36^7 = 78 billion

How to generate a short URL

We do not generate a short URL everytime, we just lookup the table

How to send request

Restful service

Restful API

Design a Database

Short URL -> Long URL, time

Pretty Easy? If we have a high QPS?

What DB we should use?

Relational Database: Oracle, MySql

Non-Relational Database (NO Sql): MangoDB, CouchDB, Couchbase, Redis

RDBMS vs NoSQL

RDBMS(Relational Database Management System)

  • Strong mathematical basis
  • Declarative syntax
  • A well-known language in Structured Query Language (SQL)
  • Real-time Read
  • Read/Write Consistency

RDBMS vs NoSQL

NoSQL (Not Only SQL)

  • It does not have schema
  • Read/Write throughput is very high
  • Horizontal scalability can be achieved easily
  • Will support Bigdata in volumes of Terra Bytes & Peta Bytes
  • Faster development life cycles for developers
  • Can be hosted in cheaper hardware machines
  • In memory caching option is available to increase the performance of queries

Lots of companies combine these two together

For this question

WE could just use NoSQL

 

Reason: we do not have complicated query to fetch data, we only need original URL and short URL (timestamp maybe)

How to remove unused links?

How to update the Store?

How to remove them?

RDBMS + NOSQL

Relational Database cannot handle high reading QPS

NOSQL has a lot limit in relation and maintenance

 

So sometimes we just hybrid them together

RDBMS + NOSQL

For common get queries, we store them in NOSQL

For specific queries and write operation, we still use RDBMS

How to update NOSQL? Database Listener

Summary

Database: Relational and NoSql -> consider to use which one

 

Network: Apache, Tomcat, etc -> Rest API, JSON

 

Distributed System: Load balancing, Sticky Session

 

Security: HTTPS, Encryption/Decryption

Copy of Copy of [GoValley-Jo] Design Part 2 14

By ZhiTongGuiGu

Copy of Copy of [GoValley-Jo] Design Part 2 14

  • 41