Ctrl K
Java · Mid-level · System design

Design a local in-memory cache for reference data in a Java service: it's read by thousands of requests per second, and the data in the source is updated every few minutes.

~10 min by voice

How to approach it

The interviewer wants to see whether you understand concurrent access in the JVM and can choose a structure and an update strategy for a "many reads, rare updates" profile: no locks on reads, no partially updated data, with memory under control and sensible behavior on failures.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsWrite a thread-safe RateLimiter class: the constructor takes how many requests per second are allowed, and the tryAcquire method, without waiting, returns true if the request can be let through and false if the limit is exhausted. It will be called concurrently from many threads. SeniorWrite an async function fetch_all that takes a list of URLs, an async function that fetches a single URL, and a limit on concurrent requests. It returns the results in the same order as the URLs, and a failure of one request must not take down the others. SeniorВозьмём перевод между двумя счетами, которые лежат в одной базе: списать с одного, зачислить на другой. Как вы это реализуете, чтобы при параллельных операциях деньги не потерялись и баланс не ушёл в минус? SeniorНесколько потоков одновременно делают counter++ над общей переменной, и в итоге значение получается меньше ожидаемого. Объясните, что именно происходит на уровне процессора и памяти, и какими способами это можно исправить — чем они отличаются внутри. Mid-levelПеред базой стоит кеш в Redis с карточками товаров, TTL — пять минут. Расскажите, как бы вы организовали чтение и обновление, как кеш может разойтись с базой, и что произойдёт, когда истечёт TTL у очень популярного ключа. Mid-level

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~10 min