Skip to content
/ refx Public

Refx is a high-performance URL shortening service built in Go, designed for speed and scalability.

Notifications You must be signed in to change notification settings

amrrdev/refx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

refx

A URL shortening service built with Go, optimized for low-latency redirects and high throughput.

Performance characteristics

Sub-millisecond redirects through Redis L1 cache with automatic fallback to PostgreSQL. Connection pooling via pgxpool eliminates handshake overhead on database queries.

Distributed ID generation using Snowflake algorithm - no database sequences, no coordination overhead, no hotspots. IDs are generated in-process with guaranteed uniqueness across instances.

Compact representation via Base62 encoding reduces URL length while maintaining readability (62 characters vs 16 for hex).

ID generation strategy

Snowflake-based 64-bit IDs composed of:

  • Uses a custom epoch (November 2023) to maximize ID space
  • Combines timestamp (milliseconds), machine ID, and sequence number
  • Thread-safe generation with mutex locks
  • No collisions even under high load

These IDs are then encoded to Base62 (a-z, A-Z, 0-9) to create compact URL-friendly codes.

Setup

Start PostgreSQL and Redis:

docker-compose up -d

Create .env file:

DATABASE_URL=postgres://refx_user:refx-password@localhost:5432/refx_db
REDIS_CONNECTION=redis://localhost:6379

Run the service:

go run cmd/main.go

API

Create short URL:

curl -X POST http://localhost:8080/api/urls \
  -H "Content-Type: application/json" \
  -d '{"long_url": "https://example.com"}'

Redirect to original URL:

curl http://localhost:8080/api/urls/{short_code}

About

Refx is a high-performance URL shortening service built in Go, designed for speed and scalability.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages