← ByteDance Interview InsightsSoftware Engineer

ByteDance·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jun 2026

Summary

Bytedance SRE interview that went pretty deep into system design territory. The main focus was building a URL shortener from scratch, and they wanted actual working code plus a real conversation about trade-offs, not just a whiteboard sketch.

Questions Asked (4)

Q1

Design and implement a TinyURL service with encode and decode functions. Walk through your short-code generation strategy and implement a working in-memory version.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

I went with counter plus base62 encoding first because it's predictable and collision-free, then they pushed me on what happens when the counter resets or you're running multiple nodes.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (scale, read/write ratio, custom aliases, expiration) and then propose a short-code generation strategy (e.g., base62 encoding of a globally unique ID). Implement a simple in-memory version using a hash map for storage and a counter or random generator for IDs, and discuss trade-offs like collision handling and scalability.

Pro tip: Mention that using a globally unique ID generator (like Snowflake) avoids collisions and allows predictable short codes, but consider the trade-off of exposing sequential IDs; alternatively, use a hash with collision resolution. Also, discuss how to handle concurrent writes and reads.

1. Clarify Requirements

Ask about expected scale (e.g., 100M URLs), read/write ratio, latency requirements, custom aliases, expiration, and analytics. This shows you think about real-world constraints.

2. Design Short-Code Generation

Propose a strategy: either base62 encoding of a unique ID (from a counter or distributed ID generator) or hashing the URL and taking a substring. Discuss collision handling and length trade-offs.

3. Implement In-Memory Version

Write a simple class with a hash map for storage and a counter for ID generation. Implement encode (generate short code, store mapping) and decode (lookup original URL).

4. Discuss Trade-offs and Scalability

Talk about limitations of in-memory (persistence, scalability) and how to extend to distributed systems (e.g., database, caching, sharding). Mention collision probability and mitigation.

Key Points to Mention

  • Base62 encoding (a-z, A-Z, 0-9) to generate compact short codes.
  • Using a globally unique ID generator (e.g., Snowflake) or a counter to avoid collisions.
  • Handling collisions via retry or pre-allocated ranges.
  • Data storage: in-memory hash map for simplicity, but discuss database and caching for production.
  • Read/write ratio optimization: caching frequently accessed URLs.
  • Custom aliases and expiration policies as potential requirements.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

How would you handle hash collisions in a URL shortening system, and what are the trade-offs between different approaches?

System DesignTechnical Trade-offs
Author's notes

Talked through retry-on-collision with a random generator, then appending a suffix to the input before rehashing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and scale of the URL shortening system, then explain how hash collisions can occur and present multiple strategies to handle them, such as open addressing, chaining, or using a unique ID generator. Compare the trade-offs of each approach in terms of performance, complexity, and scalability, and conclude with a recommendation based on the system's constraints.

Pro tip: Mention that collisions can be avoided altogether by using a distributed unique ID generator (like Snowflake) and then encoding the ID in base62, which is a common approach in large-scale systems like Bytedance's. This shows you think beyond just handling collisions to preventing them.

1. Clarify Requirements and Scale

Ask about the expected number of URLs, read/write ratio, latency requirements, and whether the short URL length is fixed. This determines the collision probability and acceptable trade-offs.

2. Explain Collision Handling Strategies

Describe approaches like open addressing (linear probing, quadratic probing), separate chaining, and using a unique ID generator with base62 encoding. Mention that collisions can also be resolved by appending a counter or rehashing.

3. Analyze Trade-offs

Compare strategies on metrics like lookup time, memory usage, implementation complexity, and scalability. For example, open addressing has better cache performance but is sensitive to load factor, while chaining is simpler but uses more memory.

4. Consider Distributed Environment

Discuss how collisions are handled in a distributed system, such as using consistent hashing or a centralized ID generator. Mention that distributed ID generators (e.g., Snowflake) can eliminate collisions by design.

5. Recommend and Justify

Based on the requirements, recommend a specific approach (e.g., unique ID generator + base62) and justify why it's suitable for the given scale and constraints.

Key Points to Mention

  • Hash function choice (e.g., MD5, SHA-256) and its impact on collision probability
  • Open addressing vs. separate chaining: performance and memory trade-offs
  • Using a unique ID generator (e.g., Snowflake) to avoid collisions entirely
  • Base62 encoding for short URL generation and its benefits
  • Handling collisions in a distributed system (e.g., consistent hashing, centralized counter)
  • Read/write ratio and caching strategies to mitigate collision resolution overhead

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Compare storage options for this service: an in-memory dictionary versus something like Redis. When does each make sense?

System DesignTechnical Trade-offs
Author's notes

Pretty straightforward.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the service's requirements—scale, latency, durability, and data sharing needs—then compare in-memory dictionaries and Redis across those dimensions. Conclude with concrete scenarios where each option is the better fit, showing you can make pragmatic trade-offs.

Pro tip: Mention that in-memory dictionaries are often the right choice for single-instance, read-heavy caches with no persistence needs, while Redis shines when you need shared state, persistence, or advanced data structures—but always consider operational overhead.

1. Clarify requirements

Ask about scale (data size, QPS), latency targets, durability, and whether multiple instances need to share state. This ensures your comparison is grounded in the actual use case.

2. Compare on key dimensions

Evaluate in-memory dictionary vs. Redis on performance, scalability, persistence, data structures, and operational complexity. Highlight that in-memory is fastest but limited to a single process, while Redis adds network overhead but offers rich features.

3. Identify suitable scenarios

Map each option to concrete scenarios: in-memory for local caching, session data in a single server, or temporary computations; Redis for distributed caching, shared sessions, rate limiting, pub/sub, and persistent stores.

4. Acknowledge trade-offs and hybrid approaches

Discuss that in-memory can be used as a first-level cache with Redis as a second-level cache, and mention that Redis can be overkill for small-scale services. Show awareness of cost and complexity.

5. Conclude with a recommendation

Based on the clarified requirements, state which option you would choose and why, or propose a hybrid solution. This demonstrates decisiveness and practical judgment.

Key Points to Mention

  • Performance: in-memory dictionary has microsecond latency and no network overhead; Redis adds network round-trip but is still sub-millisecond.
  • Scalability: in-memory is limited to a single process and doesn't scale horizontally; Redis supports distributed access and clustering.
  • Persistence and durability: in-memory data is lost on restart; Redis offers persistence options (RDB, AOF) and replication.
  • Data structures and features: Redis provides rich data types (lists, sets, sorted sets, streams) and features like pub/sub, TTL, and Lua scripting.
  • Operational complexity: in-memory requires no extra infrastructure; Redis needs deployment, monitoring, and maintenance.
  • Use cases: in-memory for local caching, temporary data, or single-instance services; Redis for shared state, distributed caching, session stores, and rate limiting.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

How would you add per-URL TTL and expiration support to your URL shortener?

System DesignAPI & Integrations
Author's notes

Redis makes this almost free with the EXPIRE command, so I led with that.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: per-URL TTL means each short URL can have a custom expiration time, and expired URLs should return 410 Gone or redirect to a default page. Then propose a design that stores expiration metadata alongside the URL mapping and handles expiration at read time and via background cleanup.

Pro tip: Mention that you would use lazy deletion on read combined with a periodic background job to avoid expensive scans, and that you'd add a 'ttl' field to the URL record with a default value for backward compatibility.

1. Clarify requirements and constraints

Ask whether TTL is set at creation time only or can be updated later, and whether expired URLs should be deleted or just return an error. Also consider if there's a default TTL for URLs without one.

2. Design data model changes

Add an expiration timestamp field to the URL mapping record. Consider using a separate table or index for efficient querying of expired URLs, and decide on a storage engine that supports TTL natively (e.g., Redis with EXPIRE, DynamoDB TTL).

3. Handle expiration at read time

When a short URL is accessed, check if the current time exceeds the expiration timestamp. If expired, return HTTP 410 Gone (or 404) and optionally trigger asynchronous deletion.

4. Implement background cleanup

Use a scheduled job or a queue-based system to periodically scan for and delete expired URLs. For large scale, use a distributed lock or sharding to avoid contention.

5. Consider API and client impact

Update the API to accept an optional TTL parameter (e.g., in seconds or as an absolute timestamp). Ensure backward compatibility and document the behavior for expired URLs.

Key Points to Mention

  • Storage options: native TTL support in databases like Redis, DynamoDB, or Cassandra
  • Lazy vs. eager expiration: checking on read vs. background cleanup
  • HTTP status codes: 410 Gone for expired URLs vs. 404 Not Found
  • Scalability: avoiding full-table scans by using indexes or time-bucketed sharding
  • API design: optional TTL parameter with a sensible default (e.g., never expire)
  • Monitoring and metrics: tracking expired URL hits and cleanup job performance

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.