Skip to Content
Overview

Source: Jolli-sample-repos/url-shortener  Last Updated: 4/8/2026


Overview

Key Design Choices

Stateless REST API - No sessions, each request self-contained

Dual-index Map storage - O(1) lookups for both shortCode and longUrl (deduplication)

// storage.ts:7-8 urls: Map<shortCode, ShortUrl> longUrlIndex: Map<longUrl, shortCode>

nanoid (6 chars) - 62^6 = 56B combinations, low collision potential.

// generator.ts:4-5 const ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; const nanoid = customAlphabet(ALPHABET, 6);

Zod validation - Type-safe schema validation at API boundary

// validator.ts:3-8 createUrlSchema = z.object({ longUrl: z.string().url(), customCode: z.string().regex(/^[a-zA-Z0-9]+$/).min(4).max(20).optional(), expiresAt: z.string().datetime().optional() });

Trade-offs

ChoiceProCon
In-memory MapFast, simpleData loss on restart
nanoid vs UUID6 chars vs 36Collision handling needed
No authFocus on core featuresProduction needs auth layer
Vanilla JSZero build, instant loadNo React features