r/developersIndia • u/noobile78 Software Engineer • Apr 05 '24
Interviews One question I ask to check potential hires for in- depth knowledge about backend systems
So I used to work for a big startup and one part of it was to take interviews of potential hires to assess their understanding about systems. There were few predefined problem from which we could ask but after sometime candidates had figured out those frequently asked problems, making them useless. So I started asking a new problem which was close to something I had solved in real life and surprisingly 9 out of 10 candidates use to get lost solving it.
Problem : Given a backend system which has a relation database(single instance) and an application server (horizontally scalable) . There is a status table in the DB which stores the status of users against a unique user id and there is an API which updates the status of the users based on the user id provided in the API request. You have to figure out a way to safely update the status when you are getting multiple request at the same time. Given the below constraints
- Status can have 3 values SUCCESS , FAILURE , PENDING
- The status can only move in certain direction e.g. PENDING -> FAILURE , FAILURE -> SUCCESS , PENDING -> SUCCESS . But movement of status like SUCCESS -> FAILURE (or any other apart from whatever is mentioned in previous statement) is not allowed. Note : You can get multiple request to update the status of the same user at the same time.
The above problem in fairly simple to explain and provides enough room to assess the candidate's thought process and problem solving skill as well as to measure their understanding of real world systems.
Yet to my surprise very few candidates were able to even comprehend the problem and understand what I am trying to get from them. IDK either this problem is a bit confusing or people are practicing too much for interviews that the minute they get something new they are unable to handle it
•
u/AutoModerator Apr 05 '24
Join Nishant Modak, CEO of Last9: An AMA on Monitoring, DevOps, Cricket Scale, Building Startups, and much more! - Apr 7th, 6:00 PM IST!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
5
u/RaccoonDoor Software Engineer Apr 05 '24
Interesting question.
Where is the API for updating the status hosted in this arrangement? Are the calls made directly to the DB or is there an intermediate service that accepts DB related API calls?
4
u/RaktPipasu Backend Developer Apr 06 '24
PENDING -> FAILURE , FAILURE -> SUCCESS , PENDING -> FAILURE.
How will state change occur for SUCCESS?
4
u/Left_Opportunity9622 Apr 06 '24
So, overall the logic would look something like this -
Assuming the request params are user_id and updated_state
Caveat: question doesn't mention how cases where user_id isn't mentioned should be handled, so haven't added the handling in this solution.
1
u/Ddog78 Data Engineer Apr 06 '24
Huh interesting. How would you answer this, OP?
1
u/un-_-known_789 Apr 06 '24
So, 1.INITIAL STATE: PENDING
2.PENDING STATE -> SUCCESS OR FAILURE
3. IF SUCCESS then NO further change.
4. ELSE FAILURE so FAILURE -> SUCCESS.
So if for user 1 initially its on pending state I got 2 req one is change it to FAILURE and another is to SUCCESS. As SUCCESS is last state we can go with this.
Ik I might getting it wrong, so pls give some hint or direct solution.
1
u/Beginning-Ladder6224 Apr 06 '24
Let's stop thinking DB for the moment - u/noobile78. You are saying given an user, it has a status map, stored along with user ID.
The status is a state machine. You want to solve the state machine problem.
As I can read, the state machine is depicted wrong. The following "must" be the transitions:
PENDING -> FAILURE
PENDING -> SUCCESS
FAILURE -> SUCCESS ( should not it be PENDING? )
( you repeated PENDING -> FAILURE 2 times ).
DB is the least of the bother, it is simple storage.
These transitions form a cyclic graph over multiple calls.
Please DM me, I am pretty much sure something is extremely fishy here, if you chose to have a conversation.
Generally I take least interest in these, but it seems a lot of folks career might depend on this, for good or bad, so it has to be thrashed out formally.