DevConnectDevConnect
Sign up · Log in

backend-task

r@ramshaanwar01

Shipped: A short link service

My internship task: a short link service For my internship task I built a small short link service, like a very simple version of bit.ly. You give it a long URL and it gives back a short code. When someone opens that code, they get redirected to the original URL, and the service counts how many times it was followed. I used FastAPI for the API, PostgreSQL for storage, SQLAlchemy and Alembic for the database layer, and Pytest for testing. What it does - Creates a short code from a URL - Redirects the short code to the original URL - Counts every follow - Returns the same code if the same URL is submitted twice - Returns 400 for a malformed URL before storing anything, and 404 for an unknown code How I built it I started with a plain Python dictionary instead of a database, so I could understand the logic first. Once the create, redirect and counting behavior worked, I moved the data into PostgreSQL. After that I wrote automated tests, and finally the README. Each stage went into its own branch and pull request, so the history reads step by step. Things I learned - 301 vs 302: a 301 is cached by browsers, so repeat visits could skip the service and never be counted. I used a 302 so every follow gets counted. - Let the database enforce rules: unique constraints on the code and the URL stop duplicates even if two requests arrive at the same moment. - Counting clicks safely: a single UPDATE clicks = clicks + 1 runs inside the database, so simultaneous visits don't lose counts. - Testing: the tests run against a separate database, so they never touch real data. - Keeping secrets out of Git: the database password lives in a .env file that Git ignores, with a .env.example showing the shape. Problems I ran into Most of my learning came from errors: psql missing from the Windows PATH, PowerShell breaking JSON quotes in curl , an environment variable coming back as None , and Pytest finding zero tests because a file was named testlinks.py instead of test links.py . Each one taught me something about how the tools actually work. I'm still a beginner in backend development, and this project helped me connect things I had only seen separately, such as HTTP status codes, databases, migrations and tests. If you have feedback or suggestions, I'd be glad to hear them. Repo: https://github.com/Ramsha-Anwar/short-link-service

2