| ID | Requirement | Key Details & Acceptance Criteria |
|---|---|---|
| FR-1 | Redirection | Service must redirect /{shortCode} to its target URL.• Returns 200/301/302 as configured.• No body on 301/302.• Preserves UTM/query unless configured to strip. |
| Daily Volume | Postgres Status | NoSQL Needed? |
|---|---|---|
| ≤ 1 M | Fully trivial | NO |
| 10 M | Fine with replicas + Redis | NO |
| 100 M | Sharding / partitioning advised | Consider ClickHouse/Mongo |
| 1 B+ | Painful for heavy writes | YES – shift analytics |
| Problem | sync Tool Used |
Key Learning |
|---|---|---|
| Ping Pong | sync.Mutex |
Protect shared state |
| Producer–Consumer | sync.Mutex, sync.Cond |
Wait/notify on conditions |
| Sleeping Barber | sync.WaitGroup, Channels |
Use channels as queues |
| Dining Philosophers | sync.Mutex, sync.WaitGroup |
Prevent deadlocks |
| Worker Pool (Fan-in/out) | sync.WaitGroup |
Aggregate worker results |
| Heartbeat–Ward | Channels, Timers | Failure detection via signals |
| Section | Purpose |
|---|---|
.text |
Executable code and static constants |
.data |
Initialized global variables |
.bss |
Uninitialized global variables, zeroed at runtime |
.rodata |
Read-only data like string literals |
| Component | Purpose |
|---|---|
| Program Headers | Instruct the OS how to map segments into memory for execution (e.g., .text, .data). |
| Symbols | Describe functions, global variables, and their offsets in the binary; used for linking, debugging. |
| Dynamic Libraries | List of shared libraries the binary depends on if it’s dynamically linked (e.g., libc.so). |
| Entry Point | The address where execution starts (runtime loader jumps here → runtime startup code → main). |
| Component | Description |
|---|---|
| G (goroutine) | Represents a single goroutine with its own stack and execution context. |
| P (logical processor) | Executes goroutines, holds a local cache (mcache) for fast memory allocation. |
| M (OS thread) | Maps P to an actual OS thread, interacts with the OS for scheduling and system calls. |
| Layer | Description |
|---|---|
| mcache (per-P cache) | Stores tiny and small objects for fast, lock-free allocation; local to a logical processor (P). |
| mspan | Contiguous memory pages from mheap; divided into slots for small objects. Local to one P while in use, not shared directly. |
| mcentral | Central free list; supplies mspans to mcache when the cache is empty. |
| mheap | Global heap shared among all processors. Allocates spans for mcentral or large objects directly. Requests memory from the OS via mmap. |
| OS |
| Type | Size | Allocation Path |
|---|---|---|
| Tiny | <16 bytes | mcache (fast path) |
| Small | 16B–32KB | mcache → mspan → mcentral → mheap → OS |
| Large | >32KB | mheap → OS (direct allocation) |
| Aspect | mspan | mheap |
|---|---|---|
| Scope | Local to P while allocated | Global, shared among all Ps |
| Allocation | Divided into slots for small objects | Provides spans to mcentral/mcache or allocates large objects directly |
| Sharing | Moves between Ps via mcentral, never shared while in use | Shared globally across all Ps |
| Locking | Lock-free while local | Locking required for global access |
| Term | Description |
|---|---|
| Concurrent | Runs alongside your goroutines without stopping the world for long periods. |
| Tri-color | Objects are tracked as: • White = unreachable (candidate for GC) • Gray = discovered, still need scanning • Black = reachable, fully scanned |
| Mark-and-sweep | The GC first marks all live objects (reachable from roots), then sweeps memory used by unreachable objects. |
OlderNewer