A URL shortener service creates a short url/aliases/tiny url against a long url.Moreover, when user click on the tiny url, he gets redirected to original url.
Tiny url are exceedingly handy to share through sms/tweets (where there is limit to number of characters that can be messaged/tweeted) and also when they are printed in books/magazines etc.(Less character implies less printing cost). In addition, it is easy and less error prone to type a short url when compared to its longer version.
Server: Node, Express, MongoDB, Redis
Problems with above design :
There is only one WebServer which is single point of failure (SPOF) System is not scalable There is only single database which might not be sufficient for 60 TB of storage and high load of 8000/s read requests
POST /app/users/api/create
Body | Type | Description |
---|---|---|
email |
string |
Required. Your email |
password |
string |
Required. Your password |
passwordConfirmation |
string |
Required. Your password confirmation |
POST /app/users/api/login
Body | Type | Description |
---|---|---|
email |
string |
Required. email |
password |
string |
Required. password |
POST /app/api/create
Body | Type | Description |
---|---|---|
API_KEY |
string |
Required. Your API_KEY |
URL |
string |
Required. URL to be shorten |
GET /${SHORT_URL}
Parameters | Type | Description |
---|---|---|
SHORT_URL |
string |
Required. the SHORT_URL assigned with original one |
└── URL-shortener/
├── config/
│ └── default.ts
├── src/
│ ├── controllers/
│ │ ├── url.controller.ts
│ │ └── user.controller.ts
│ ├── errors/
│ │ └── APIError.ts
│ ├── middleware/
│ │ ├── errorHandler.middleware.ts
│ │ ├── logger.middleware.ts
│ │ └── validateInput.middleware.ts
│ ├── models/
│ │ ├── url.model.ts
│ │ └── user.model.ts
│ ├── routes/
│ │ ├── index.ts
│ │ ├── url.route.ts
│ │ └── user.route.ts
│ ├── schema/
│ │ ├── url.schema.ts
│ │ └── user.schema.ts
│ ├── services/
│ │ ├── url.service.ts
│ │ └── user.service.ts
│ ├── utils/
│ │ ├── connect.ts
│ │ └── logger.ts
│ └── server.ts
├── .env.example
├── .eslintrc.js
├── .prettierrc.json
├── package.json
├── tsconfig.json
└── yarn.lock
git clone https://github.com/jrmoha/URL-shortener.git
cd URL-shortener
yarn add typescript
npx tsc --init
yarn install
yarn dev
Find all in .env.example