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
| Choice | Pro | Con |
|---|---|---|
| In-memory Map | Fast, simple | Data loss on restart |
| nanoid vs UUID | 6 chars vs 36 | Collision handling needed |
| No auth | Focus on core features | Production needs auth layer |
| Vanilla JS | Zero build, instant load | No React features |