A URL shortener built from the ground up in C# without using ASP.NET Core or existing web frameworks. The goal of this project is to understand how web servers and backend frameworks work internally by implementing each layer manually.
This project is evolving into a complete distributed backend system, including a custom web server, router, Redis-compatible cache, rate limiter, and load balancer.
- Learn how HTTP works over raw TCP sockets.
- Build a custom web server from scratch.
- Implement a routing engine similar to ASP.NET Core.
- Build backend infrastructure without relying on existing frameworks.
- Explore distributed systems concepts by integrating custom infrastructure components.
- Gain hands-on experience with networking, concurrency, caching, and scalability.
- Listens for incoming TCP connections.
- Parses raw HTTP requests.
- Sends properly formatted HTTP responses.
- Supports multiple concurrent clients using asynchronous programming.
- Parses the request line.
- Parses HTTP headers.
- Parses query parameters.
- Reads request bodies using the
Content-Lengthheader.
Supports:
- Static routes
- Dynamic route parameters
- GET requests
- POST requests
Example routes:
GET /hello
GET /hello?name=Bryan
POST /shorten
GET /{shortCode}
- Accepts long URLs through a POST endpoint.
- Generates unique short codes.
- Stores URL mappings in memory.
- Resolves short codes back to their original URLs.
- Redirects clients using HTTP 302 responses.
BasicWebServer/
│
├── Models/
│ ├── HttpRequest.cs
│ ├── HttpResponse.cs
│ └── Route.cs
│
├── Routing/
│ └── Router.cs
│
├── Services/
│ ├── UrlStore.cs
│ └── ShortCodeGenerator.cs
│
├── Program.cs
│
└── BasicWebServer.csproj
POST /shorten
Content-Type: application/jsonBody
{
"url": "https://google.com"
}{
"shortCode": "abc123"
}GET /abc123HTTP/1.1 302 Found
Location: https://google.comGET /hello?name=BryanHello, Bryan
Clone the repository:
git clone https://github.com/<your-username>/<your-repository>.gitNavigate to the project directory:
cd BasicWebServerRun the application:
dotnet runThe server listens on:
http://localhost:8080
Open:
http://localhost:8080/hello
Expected response:
Hello, world
Open:
http://localhost:8080/hello?name=Bryan
Expected response:
Hello, Bryan
Using curl:
curl -X POST http://localhost:8080/shorten \
-H "Content-Type: application/json" \
-d "{\"url\":\"https://google.com\"}"Expected response:
{
"shortCode": "abc123"
}Windows PowerShell: The
curlcommand syntax differs from Bash. You may prefer usingInvoke-RestMethodor adjust quoting accordingly.
Open:
http://localhost:8080/abc123
The browser should automatically redirect to:
https://google.com
Client
│
▼
TCP Listener
│
▼
HTTP Request Parser
│
▼
Router
│
▼
Route Handler
│
▼
HttpResponse
│
▼
Client
- Middleware pipeline
- Request logging
- Exception handling
- Better HTTP header support
- Persistent connections
- Static file serving
- URL validation
- Custom aliases
- URL expiration
- Click analytics
- Duplicate URL detection
- Replace in-memory storage with a custom Redis server.
- Implement a distributed API rate limiter.
- Build a custom application load balancer.
- Support multiple backend server instances.
- Health checks.
- Fault tolerance.
- Horizontal scaling.
- Docker support.
- Automated integration tests.
- GitHub Actions CI.
- Performance benchmarks.
- Metrics endpoint.
- C#
- .NET
- TCP Sockets
- HTTP/1.1
- JSON
- Asynchronous Programming
This project focuses on understanding backend engineering fundamentals by implementing core infrastructure manually instead of relying on existing frameworks. The long-term objective is to evolve this project into a distributed system composed of independently developed infrastructure components such as a custom Redis server, API rate limiter, and load balancer.
- ✅ Build a custom TCP web server
- ✅ Parse HTTP requests manually
- ✅ Implement a custom routing engine
- ✅ Build an in-memory URL shortener
- ⏳ Implement middleware pipeline
- ⏳ Build a custom Redis server
- ⏳ Integrate Redis into the URL shortener
- ⏳ Implement distributed API rate limiting
- ⏳ Build a custom application load balancer
- ⏳ Deploy multiple backend instances behind the load balancer