VDesign a URL shortener. Where are the bottlenecks?
Питання інтерв’юераSystem Design
Єдиного правильного дизайну не існує. Інтерв’юери оцінюють, як ви уточнюєте задачу, як міркуєте про цифри та як пояснюєте компроміси. Говорити в зрозумілому порядку важливіше, ніж називати багато технологій.
Користуйтеся фіксованою структурою й проговорюйте її вголос: вимоги, орієнтовні цифри, простий дизайн, потім вузькі місця та масштабування. Коли ви кажете "now I will estimate the load", інтерв’юер розуміє, що ви робите, а ви отримуєте мить на роздум.
- ✓Слова → фрази → речення → мовлення
- ✓Зміст відповіді
- ✓Мова
Поширені запитання та зразки відповідей
Design a URL shortener. Where are the bottlenecks?
Спроєктуйте скорочувач посилань. Де вузькі місця?
Що хоче почути інтерв’юер. Спершу уточнювальні запитання, потім простий дизайн, далі справжнє вузьке місце: читання та унікальні коди.
Зразок відповіді англійською для тренування вголосFirst I clarify the requirements: how many new links per day, how many redirects, and whether links expire. Let us say 100 million new links a month and a hundred times more reads. The design is simple: an API to create a link, a service that generates a unique short code, a database that maps the code to the URL, and a redirect service with a cache. Reads are the main load, so I put a cache in front of the database and use a store that scales for key-value access. The hard part is generating unique codes without collisions, for example with ranges of a counter given to each server, and base-62 encoding. I would also add rate limiting against abuse.
How do you structure your answer in a system design interview?
Як ви структуруєте відповідь на співбесіді із system design?
Що хоче почути інтерв’юер. Повторюваний порядок, який ви проговорюєте вголос.
Зразок відповіді англійською для тренування вголосI follow the same order every time. First, I ask about requirements, both functional and non-functional, like latency and availability. Second, I make a rough estimate of the traffic and the storage, so I know the scale. Third, I draw a simple high-level design with the main components and the data model. Then I go deeper into the part that matters most, usually the data store or the bottleneck. At the end I discuss failure, monitoring and how the system can grow. I say each step aloud, so the interviewer can follow my thinking and guide me.
How would you use a cache, and what are the risks?
Як би ви використали кеш і які в нього ризики?
Що хоче почути інтерв’юер. Названий патерн, строк життя записів і щонайменше два реальні ризики.
Зразок відповіді англійською для тренування вголосI would use a cache for data that is read often and changes rarely. The most common pattern is cache-aside: the application checks the cache first, and on a miss it reads from the database and saves the result with a time to live. The risks are stale data, a cache stampede when a popular key expires and many requests hit the database together, and an unclear invalidation strategy. To reduce these risks, I choose a sensible expiry time, add a small random variation to it, and decide how much stale data the business accepts.
How do you scale a database?
Як масштабувати базу даних?
Що хоче почути інтерв’юер. Розумний порядок: спершу прості кроки, потім репліки, потім шардування з його ціною.
Зразок відповіді англійською для тренування вголосI start with the simplest options: better indexes, query tuning and a bigger machine. Then I add read replicas, which help when reads dominate, but replicas can lag behind the primary. When writes or data size become the problem, I use sharding: splitting data by a key, such as a user ID, across several databases. Sharding brings complexity. Queries across shards are hard, and moving data between shards is painful. So I pick the shard key carefully and delay sharding until it is really needed.
How do you talk about trade-offs and consistency?
Як ви говорите про компроміси та узгодженість?
Що хоче почути інтерв’юер. Кожне рішення названо разом із ціною та прив’язане до продукту.
Зразок відповіді англійською для тренування вголосI try to say each decision together with its cost. For example, I choose eventual consistency for a news feed, because it gives lower latency and higher availability, and users can accept a delay of a few seconds. For payments, I choose strong consistency, because correctness is more important than speed. When a network partition happens, a distributed system must choose between consistency and availability, and I explain which one the business prefers for each part of the system. This shows that I think about the product, not only about technology.
Як вимовляти ключові терміни
- scalability
- скейлабі́літі
- sharding
- ша́рдинг
- cache
- кеш
- availability
- евейлабі́літі
- latency
- ле́йтенсі
- bottleneck
- бо́тлнек
Корисні фрази для відповіді
- Let me clarify the requirements first.Спершу дозвольте уточнити вимоги.
- Can I assume that…?Чи можу я припустити, що…?
- Let me do a rough estimate.Зроблю орієнтовну оцінку.
- The main bottleneck here is…Головне вузьке місце тут —…
- The trade-off is…, so I would choose…Компроміс такий:…, тому я б обрав…
- To summarise the design,Підсумую дизайн:
- If we have time, I would go deeper into…Якщо буде час, я б заглибився в…
Типові помилки
- Починати малювати, не поставивши запитань. Перші хвилини віддайте вимогам.
- Мовчати, поки думаєте. Скажіть "I need a moment to think about the data model", щоб інтерв’юер знав, що ви працюєте.
- Називати багато технологій без причин. Оберіть одну й поясніть, чому вона підходить.
- Ігнорувати збої та моніторинг. Одне речення про те, що відбувається, коли вузол виходить з ладу, показує досвід.
Часті запитання
Чи потрібні цифри на співбесіді із system design?
Так, приблизні. Називайте їх уголос: запити за секунду, обсяг сховища за рік. Вони не мусять бути точними, але показують, що ви думаєте про масштаб.
Що робити, якщо я не знаю технології, яку назвав інтерв’юер?
Скажіть про це й міркуйте від потрібних вам властивостей: "I have not used it, but if it is a key-value store with low latency, I would use it for…"
Як довго можна говорити без паузи?
Не більше хвилини-двох. Зупиняйтеся в природних місцях і питайте: "Does this direction make sense to you?"
Прочитати відповідь — не те саме, що промовити її. Потренуйте кожне запитання вголос, а потім порівняйте зміст і мову власної відповіді.
Спробувати SpeakRole ↗Інші теми в цьому напрямі