Backend Engineering Project

HashRoute

A high-performance, layered URL Shortener API focusing on scalability, reliability, and clean architecture principles.

Project Overview

HashRoute was engineered to solve the challenge of mapping long, complex URLs to short, manageable identifiers at scale. The system prioritizes correctness, idempotency, and low latency.

Scalability

Designed with a stateless API layer and indexed database schema to handle high-concurrency redirection traffic.

Reliability

Collision-resistant hashing and robust error handling ensure that every short link works every time.

System Architecture

The system follows a strict layered pattern to ensure separation of concerns and maintainability.

API Layer

FastAPI handles routing, request validation via Pydantic, and dependency injection for service access.

Service Layer

Contains core business logic, including the hashing strategy and collision retry mechanisms.

Data Layer

SQLAlchemy ORM manages persistence with optimized indexes on short codes for constant-time lookups.

Request → Redirect Flow

URL Shortening Lifecycle
1. Client POSTs long URL
2. API validates URL structure
3. Service generates Base62 hash of URL
4. Collision check in Database
5. Result persisted & ID returned
6. Future GET requests redirect via HTTP 307

Using HTTP 307 (Temporary Redirect) ensures that the client eventually hits the backend again if rules change, while preserving the request method.

API Demonstration

POST /shorten
// Request
{
  "original_url": "https://docs.fastapi.tiangolo.com/..."
}

// Response (201 Created)
{
  "short_code": "x7k9p2",
  "short_url": "http://hr.io/x7k9p2",
  "created_at": "2024-02-10T15:30:00Z"
}

The API is fully documented with Swagger UI, providing interactive testing capabilities for developers.

Testing & Verification

Automated Suites

Comprehensive tests covering shortening logic, redirection, and edge cases like expired links or duplicate URLs.

pytest output
PASSED tests/test_shortener.py::test_create_url
PASSED tests/test_shortener.py::test_redirect_success
PASSED tests/test_shortener.py::test_idempotency

Interactive Concept Demo

Experience the URL shortening lifecycle in real-time. This demo simulates the backend process without making actual API calls.

1 Validating Architecture
2 Generating Base62 Hash
3 Collision Check
4 Simulating Persistence