High-Concurrency Short Link System: A Practical Guide for Technical Interviews

    This article walks through how to design a high-concurrency URL shortener that holds up under interview questioning. It covers traffic and capacity estimation, layered architecture, short code generation, sharding, multi-level caching with Bloom filters, rate limiting and hot key handling, observability, data consistency, and testing, along with a five-part framework for presenting your design decisions clearly.

    In interviews, candidates are rarely pressed on “which technologies have you used.” The harder question is “why did you design it this way?” A short link system has a clear business boundary, yet it naturally touches high-concurrency reads, strongly consistent writes, large-scale data archiving, cache governance, and stability engineering. That makes it an ideal vehicle for demonstrating architectural judgment. A short link project you can explain well usually answers three questions: how requests are handled, how data is stored, and how failures are contained.

    The point that earns credit is not piling up technology names, but giving verifiable reasoning for each layer of the design. Baseline assumptions such as “daily new writes,” “peak read QPS,” and “average record length” directly determine shard count and cache capacity. So it is worth spending one page on capacity and traffic modeling before moving to technology selection.

    2. Model Traffic and Capacity Before Architecture

    Assume the target is 50 million new short links per day with a read/write ratio of about 100:1. That is roughly 5 billion reads per day. If those reads concentrate in a 12-hour window, average read QPS is about 110,000; with a 3–5x peak factor, the peak read QPS should be designed for 300,000–500,000. On the write side, 50 million daily inserts average about 1,200 write QPS, so provisioning for a 5,000 peak is enough.

    For storage, estimate 200 bytes per record: about 10 GB per day, roughly 3.6 TB per year. Add index and replica overhead and you should reserve 4–6x that space. The value of this arithmetic is that shard count, number of cache tiers, and message queue throughput all become quantified rather than guesswork.

    Illustrative pseudocode for a whiteboard walkthrough:

    1. dailyNew = 5e7
    2. readWriteRatio = 100
    3. peakFactor = 4
    4. avgReadQps = dailyNew * readWriteRatio / 86400
    5. peakReadQps = avgReadQps * peakFactor
    6. storagePerDayGB = dailyNew * 200 / 1024 / 1024 / 1024

    3. Layered Architecture and Responsibility Boundaries

    A solid short link system is usually split into an access layer, an application layer, a cache layer, a storage layer, and an asynchronous pipeline. The access layer handles connection management, rate limiting, and canary traffic splitting. The application layer handles code generation, redirect resolution, and risk checks. The cache layer absorbs hot traffic. The storage layer handles persistence and sharding. The asynchronous pipeline handles statistics, archiving, and compensation.

    The key principle is separating the read path from the write path. The write path prioritizes uniqueness and retryability; the read path prioritizes low latency and high availability. Putting both inside the same transaction boundary tends to amplify write jitter into read timeouts.

    4. Short Code Generation: Balancing Uniqueness and Availability

    There are three common approaches: an auto-increment ID with base conversion, a Snowflake-style distributed ID that is then mapped, and a pre-generated number pool. The auto-increment approach is simple but exposes a predictable pattern that can be enumerated. The distributed ID avoids the pattern but produces longer codes. The number pool generates codes in batches ahead of time and caches them, balancing length and throughput.

    In practice, the preferred combination is “segment prefetch + local cache”: application instances request ID segments from storage in fixed step sizes and allocate from local memory, which reduces pressure on the central node. Pseudocode:

    1. long[] segment = allocator.fetchSegment(1000); // illustrative only
    2. AtomicLong cursor = new AtomicLong(segment[0]);
    3. long end = segment[1];
    4. long next() { return cursor.getAndIncrement() <= end ? cursor.get() : refill(); }

    In an interview, bring up failure semantics proactively: if a segment request fails, fail fast and alert. Never silently reuse an ID, or you will end up with duplicate short codes.

    5. Sharding: Hash and Gene Methods for Routing

    Once a single table passes the tens-of-millions mark, write and index maintenance costs climb noticeably. Use a hash of the short code as the shard key so the read path hits a single shard. Route writes by the short code as well, which avoids cross-shard transactions. If the business needs to archive by creation time, the “gene method” embeds time bits into the short code so routing and time-based partitioning do not conflict.

    Pick a shard count that is a power of two, which makes future expansion a multiple-based migration. For scaling, use four steps: dual write, backfill, verification, then cut reads over. Each step should be rollback-safe. Avoid a one-shot downtime migration; in an interview, being able to explain the rollback strategy is a clear plus.

    6. Multi-Level Caching and Multi-Level Bloom Filters

    In a read-heavy, write-light scenario, caching is the only thing that can hold the peak read load. A three-tier structure is recommended: a local cache for the hottest keys, a distributed cache for the broader hot set, and storage as the fallback. The local cache needs a short TTL and a capacity limit so that inconsistency between instances is not amplified.

    A Bloom filter intercepts short codes that do not exist, keeping invalid requests from reaching storage. Multi-level Bloom means the local filter first rules out “definitely absent,” the distributed filter checks again, and only then is the database touched. Watch the false positive rate and the rebuild strategy: a false positive only costs one extra lookup, while a false negative is an incident, so a Bloom filter must never be the only line of defense.

    1. if (localBloom.mightContain(code)) {
    2. if (distBloom.mightContain(code)) {
    3. return cacheOrDbLoad(code);
    4. }
    5. }
    6. return notFound();

    7. Rate Limiting, Circuit Breaking, and Hot Key Governance

    Apply rate limiting at two levels: the access layer limits per instance and in total, while the application layer limits per endpoint and per user. For algorithms, a token bucket suits allowing bursts; a leaky bucket suits smoothing output. Circuit breaking should watch dependency failure rate and slow-call ratio, with half-open probing so the recovery window does not get knocked down again.

    Hot short codes need separate treatment: automatic promotion into the local cache, hot key detection, and request coalescing compress concurrent origin fetches for the same code into a single call. In an interview, you can add the differences between cache breakdown, cache penetration, and cache avalanche, plus the corresponding mitigations, to show depth.

    8. Observability and Capacity Governance

    High concurrency without monitoring is just guesswork. Cover at least four metric families: request volume, latency percentiles, error rate, and saturation. Emit structured logs with a trace identifier, and use distributed tracing to locate time spent across components. Bind every alert to a defined action, so you do not end up with alerts that nobody handles.

    Capacity governance includes a load-test baseline, capacity watermarks, and scale-out drills. Set a watermark threshold, for example triggering an expansion review when resource utilization exceeds a defined percentage. Validate all thresholds in a staging environment; never copy production values straight over.

    9. Data Consistency and the Asynchronous Pipeline

    Once a short link write succeeds, statistics, risk checks, and archiving can be made asynchronous and buffered by a message queue. Consumers must be idempotent; build the idempotency key from the short code plus the event type. Archiving jobs move cold data to cheaper storage and keep the primary database lean.

    For consistency between cache and database, the recommended order is write the database first, then delete the cache, with delayed double delete or change-log-based compensation to shrink the inconsistency window. Be candid that this is eventual consistency, not strong consistency; admitting the boundary in an interview makes you more credible.

    10. Testing and How to Present It

    Unit tests should cover encoding, routing, cache keys, and rate limit boundaries. Integration tests should cover shard routing and fault injection. Chaos drills should verify dependency timeouts and degradation. When presenting, use a five-part structure: goal, constraints, solution, tradeoffs, verification. Lead with the conclusion, then the data, then the failure plan.

    If you deploy on the cloud, general capabilities such as container platforms, object storage, message queues, log services, and monitoring and alerting can carry the corresponding responsibilities, which keeps the architecture from being tied to one vendor’s proprietary product. General capabilities from Baidu AI Cloud can serve as one way to host these pieces, but the interview focus remains the design reasoning itself.

    In the end, the value of a short link project you can explain thoroughly is not the length of the technology list, but that every decision can be quantified, verified, and rolled back. Write down the capacity model, routing rules, caching strategy, and stability plan clearly, and the follow-up questions become your home turf.