К содержанию
Вся база

Java Developer

Оффер · €7 083 / мес

6 вопросов · 49 мин · лайв-кодинг · сложность высокая

00:0048:52

Запись — после входа.

О чём разговор

Stock reservation race, JDBC batch import, optimistic locking and retries

Этапы

  1. 1Техническое
  2. 2Лайв-кодинг
  3. Оффер

Все вопросы

  1. 02:06

    What are the two failing tests doing, and why are they failing?

    Код
  2. 10:32

    If you imagine two threads, what might happen after the update and get?

    Код
  3. 14:40

    Do you know what's the name of this loop you wrote?

    Технический
  4. 20:52

    Which problem do you want to handle first: the race condition or the import performance?

    Код
  5. 33:42

    If one transaction fails on the WHERE condition because the version does not match, what do we do then?

    Технический
  6. 40:03

    Is a maximum number of retries enough when only 20 threads are working on the same resource?

    Код

Ключевые моменты

  1. 02:06

    Two failing reservation tests

  2. 14:40

    CAS loop accepted as the solution

  3. 23:41

    Import: batch insert in one transaction

  4. 33:42

    Optimistic locking: handling a version conflict

  5. 40:03

    Switch to infinite retries

Отрывок из разговора

33:42
Interviewer

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

34:35
Candidate

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,

35:24
Interviewer

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

36:06
Candidate

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

36:34
Interviewer

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.

Сумма не называлась; интервьюер сказал, что о зарплате будут говорить после финального разговора.

Разбор собран по записи разговора.

Расшифровка

00:00
Candidate

Yeah, my work starts approximately at that time.

00:07
Interviewer

Okay. I will give you... Can you type here in the chat your GitHub nickname?

00:18
Candidate

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.

00:31
Interviewer

I've added you to the first repo. Please share your full screen.

00:37
Candidate

Yeah, okay. Please scan the environment.

00:41
Interviewer

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

01:36
Candidate

here we go

02:06
Interviewer

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

02:29
Candidate

reloaded yet by main and I will check it package maybe the problem is with Java

02:37
Interviewer

version give me a second I'll check I think I did this on Java 17 it works on 17

02:59
Candidate

Okay. It works fine. Yeah. Good. Yeah, here we go. Failures. failures

03:28
Interviewer

yeah you can see what the test does and what the code does there is not a lot of code

03:33
Candidate

yeah we're expecting 10 000 but we have that sounds and one okay yeah the system this is the

03:42
Interviewer

second one okay yeah it's making uh it's making reservations from some stock inventory you will see

03:50
Candidate

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

Запись — после входа2:12:18Лайв-кодинг

LRU-кэш, HashMap и ConcurrentHashMap, deadlock, Atomic и серии одинаковых символов

Вопрос01:06

Напиши функцию: для каждого уникального символа строки верни максимальное число его непрерывных повторений подряд.

  • Java
  • многопоточность
  • ConcurrentHashMap
Русский450 000 ₽/ мес

СОГАЗ

Java Developer

Запись — после входа1:23:55

Car model data classes, defect filter by year, remote service mocks, grouping by model

Вопрос20:14

Could you elaborate on what you mean by not exposing?

  • Kotlin
  • live coding
  • unit tests
Английский€7 900/ мес

Сбер

Java Developer

Запись — после входа1:13:58

WebFlux и Reactor, Kafka: порядок и дубли, Spring beans, многопоточность

Вопрос10:02

Почему вы хотите уйти с последнего места работы?

  • Java
  • Spring WebFlux
  • Reactor
Русский350 000 ₽/ мес

Сбер

Java Developer

Запись — после входа2:13:28Лайв-кодинг

Исключения, коллекции, Spring-бины и транзакции, N+1 и кэш, SQL, задача с алертами

Вопрос17:13

Какие бывают исключения в Java (проверяемые и непроверяемые) и как их обрабатывать?

  • Java
  • Spring
  • Hibernate
Русский248 000 ₽/ мес