О чём разговор
Stock reservation race, JDBC batch import, optimistic locking and retries
Этапы
- 1Техническое
- 2Лайв-кодинг
- Оффер
Все вопросы
- 02:06
What are the two failing tests doing, and why are they failing?
Код - 10:32
If you imagine two threads, what might happen after the update and get?
Код - 14:40
Do you know what's the name of this loop you wrote?
Технический - 20:52
Which problem do you want to handle first: the race condition or the import performance?
Код - 33:42
If one transaction fails on the WHERE condition because the version does not match, what do we do then?
Технический - 40:03
Is a maximum number of retries enough when only 20 threads are working on the same resource?
Код
Ключевые моменты
- 02:06
Two failing reservation tests
- 14:40
CAS loop accepted as the solution
- 23:41
Import: batch insert in one transaction
- 33:42
Optimistic locking: handling a version conflict
- 40:03
Switch to infinite retries
Отрывок из разговора
The query is fine now. Yeah, I mean, if we are talking so far, what you did is good. But if we are talking about optimistic concurrency, what do we still need to do? Where is this method called? Please decrease stock. Okay, here. So here we
If the version is not matching, we need to specify the... Usually we're doing that in declarative way. So we're creating the optimistic exception, optimistic local exception and specifying what we will do on that. Sometimes it makes sense,
That's correct. Okay. In that particular case. Sure. That's the correct line of thinking. I'm sorry to interrupt you, but. Okay. Yeah. That's correct. The options you presented are correct and it was not really clear from the task and what
optimistic concurrency the data is protected but yeah let's think about usually if we want to reserve everything i mean if we have several resources that you want to reserve and if we want to check if it is already updated and then go to an
let's go with that one okay skip-locked is a nice mechanism to use some sometimes it's true but we don't need to use it here we can I would like to see the Let me try, yeah.
Что вынести
A live-coding Java technical interview built on three tasks: a race condition in stock reservation, slow product import, and a lost update in the database. The candidate fixed the first with a CAS loop on AtomicInteger, the second with JDBC batching in one transaction, and the third with optimistic locking and retries. The interviewer accepted all three approaches and said the decision would come in early January, after a final call with a co-founder.
Сумма не называлась; интервьюер сказал, что о зарплате будут говорить после финального разговора.
Разбор собран по записи разговора.
Расшифровка
Yeah, my work starts approximately at that time.
Okay. I will give you... Can you type here in the chat your GitHub nickname?
So I can give you access to the first. Okay, okay. I have several githubs so I'm trying to figure out what we can use for now.
I've added you to the first repo. Please share your full screen.
Yeah, okay. Please scan the environment.
Okay, you can just open. You will not need your project. You will just open my project when you clone it. okay sure so what we have inventory reserve okay yes but uh we will not we will not need the api we have uh we have tests that uh that use the api also we have we have tests that use this the service code directly by passing the api so the api is not so important but you can you can look through the code yeah i would i would yeah download this clone it locally whatever i think you have this get yeah yeah that's it
here we go
So the two tests that we have, they are failing. So you just need to figure out what the tests are doing and why they are failing. What is this, Jupiter? Maybe the project has not been
reloaded yet by main and I will check it package maybe the problem is with Java
version give me a second I'll check I think I did this on Java 17 it works on 17
Okay. It works fine. Yeah. Good. Yeah, here we go. Failures. failures
yeah you can see what the test does and what the code does there is not a lot of code
yeah we're expecting 10 000 but we have that sounds and one okay yeah the system this is the
second one okay yeah it's making uh it's making reservations from some stock inventory you will see
go through the code oh yeah this is just one several methods here so uh this is concurrent inventory service what he's doing i will look at long by line by line okay okay so we have a data structure for figuring it out and a string as a name okay sounds good atomic integer for some values it's final okay so inside constructor what we are doing for each so we put in some values inside right okay yes specifying it inside inside the initial while we're creating the object so while we reserve what we are doing we're getting it from our collection by item ID specifying it as a counter after that if counter okay now unknown item quantity less equals zero it must be positive okay yeah looks like and resolve we have some not not atomic operation atomic integer count as I as I got from assertion error I don't know the specific error but let's
Дальше — после входа. Это бесплатно и займёт минуту.
Войти и читатьПохожие собеседования
VK
Java Developer
LRU-кэш, HashMap и ConcurrentHashMap, deadlock, Atomic и серии одинаковых символов
Напиши функцию: для каждого уникального символа строки верни максимальное число его непрерывных повторений подряд.
СОГАЗ
Java Developer
Car model data classes, defect filter by year, remote service mocks, grouping by model
Could you elaborate on what you mean by not exposing?
Сбер
Java Developer
WebFlux и Reactor, Kafka: порядок и дубли, Spring beans, многопоточность
Почему вы хотите уйти с последнего места работы?
Сбер
Java Developer
Исключения, коллекции, Spring-бины и транзакции, N+1 и кэш, SQL, задача с алертами
Какие бывают исключения в Java (проверяемые и непроверяемые) и как их обрабатывать?