← Home | Writing | LinkedIn | Resume

URL shortener with nextwork's guide

following are the notes i wrote as i did the project

I worked through NextWork's URL shortener project and took notes in a file as I went. Rather than turn those into a tidy tutorial, I'm publishing them as they were written.

Python · Flask PostgreSQL Redis Docker Compose Base62

The code is on GitHub: aroonsekar/url-shortner. The guide I followed is NextWork's URL shortener project.

notes
12:02 pm

Creating a URL-Shortner following instructions from Nextwork.

First starting with a brief intro about what a url shortner, why to use it and what is the system design behind it.

Then choices of stack, Python Flask Api , PostgreSQL, Redis cache, Docker, .

Seems like Python Flask API is used as both server as well as an API layer depending on how we use it. Like when I write it in the code, its basically an API layer(when we look at the code its like we mention how the data is handled etc.. ) and when we look at the architecture of the application/ program, it acts as a server listening to the network ports

Redis, basically as a cache to store hot data, for fast lookups and all and PostgreSQL, the database for persistent storage.

So the architecture was like User first create the short URL, which is stored in the PostGre db as original url with short url. when user tries to access the short URL, first the query is sent to redis cache and checked if the URL exists in the cache so we can serve it immediately, like quickly (fast lookup), if not the URL will be checked in Postgres and then given to the user(it'll be slow compared to the serve by redis), also once served, I think we'll store that in redis, in case if the user again access it we can give it to them quicky.

12:21 pm

1. The guide asked to setup the environment, like terminal, folder setup, docker installation and cursor installation. I already created the folders, already have docker sorted and instead of cursor, I'll be using Antigravity as I have been using it for almost a year now ?..since it released.

12:27 pm

It is actually a really really good guide for a beginner, Setting up the environment, asking questions, giving out ways to check if the stack is installed properly, like verifying the docker version, verifying the path of the folder. Amaze!

12:29 pm

But can we do it only with cursor ? ..for a beginner you give them a proper guide thats brilliant, but I prefer Antigravity, 2 reasons,1. It's literally the same, 2. I have already got everything setup, 3. Im lazy.

12:32 pm

So, I have successfully developed and deployed 4 mobile apps (8, 4 in app store, 4 in playstore), but it was all self taught and I wouldnt say im confident enough and my techincal vocab isnt strong enough to say or explain the things I wanted to, in the way I actually intent to. This Course..course? or a guide..whatever is helping me with that.

12: 34 pm

We're dont with setting up the environment and tools, next up is creating the infra for the multi-service achitecture(multiple independent, tiny service, all coordinating for the main program.)

12:36 pm

so they are giving out prompts that I should paste in the chat of the IDE, cursor with Auto model selection thhey said, I have a better one, Claude code xD.

First building the docker-compose.yml.(I already work with docker, CI/CD for the mobile app backend.)

12:40 pm,

The document also give the contents for the docker-compose.yml.

12:41 pm

The guide though, it asks for screenshots as we complete some main steps..I cant be bothered..

12:43 pm

It's been a while since I have worked or even used EdTech apps, but this is good.

12:45 pm

Next the requirements file with specific versions of flask, redis and postgre

12:47 pm

A dockerfile inside app to spin up the container with the reqirements

12: 48 pm

init.sql to create table if it doesnt exist. it has id, original_url and the timestamp..

why SQL over noSQL, first of all its structured..like proper structure, then we need ACID, atomicity(all or nothing), consistency, isolation of data and durabilty. also auto increase the ids with base62 encoding

12:56

Took a little side turn, explored about base62, base64, conversions from base 10 to 62 vice versa ..interesting..

12:58 pm

Now before wbuilding the URL shortner logic, just verfitying the docker compose config..

------ took a break! ------
13:23

copy pasting the logics to setup the db, redis, base62, functions to connect to db, shorten the URl,redirect th url, encode, decode, and a quick health check endpoint.

------ Distracted for a while ------
14:06

So everything is done now. Im doing a list of tests.

  1. to see if docker is up
  2. checking status of each service
  3. then curling the health endpoints
  4. adding values in db via curl
  5. then checking docker logs to see the endpoints hit, caching stats
  6. then clearing redis cache
  7. checking the status
  8. again seeding the data and checking the logs
← All posts