I got the following interview question:

Say the company has this event, where we will create a button on a website and only the first ten clicks will be accepted and win a prize. Assume that there a millions of people around the world participating in this event. How would you implement it?

My answer:

Just save every click in the database, sort them by create time ASC, then get the first ten.

My answer was challenged with an additional question:

What if there are multiple server nodes handling this process? How would you ensure the integrity of the data? That what the database would come up with is really the first ten clicks?

That's where I got lost. I just answered let these nodes operate on a single database, or check the logs across nodes the compare them, blah blah blah. But it seems it's not the answer that was looked for.

Why doesn’t my answer address the issue and how could this scenario be solved.

PS: I was applying for a team that handles the finance/payment system of our company so I think this is something related to what the team does.

  • 3
    Even on a place as small as the Earth, if you are talking milliseconds, light only travels 186 miles, and Einstein shows there is no "simultaneous". Not to mention network latency. Ultimately it is impossible to say who were truly the first 10 to click.
    – user949300
    Mar 27 at 15:29
  • @gnat I've seen it and I don't get your point. I don't think the question is broad at all. The question clearly defines the problem and I've even shared my answer. Mar 27 at 15:31
  • I dared to reword slightly your question which is indeed interesting and could be handled objectively. Opinion based questions are out of scope and interview tag relates to recruitment process, which is not software engineering. I hope you agree with it. If not, don’t hesitate to revert it.
    – Christophe
    Mar 27 at 16:28
  • "I was applying for a team that handles the finance/payment system of our company so I think this is something related to what the team does." I highly, highly doubt it, anyone who operates at scale where they expect millions of requests per second, they would understand that such thing is impossible. Just simple network latency can result in widly different results for all clients. A single lost packet, or packet taking slightly longer route than normal can be difference between winning and loosing.
    – Euphoric
    Mar 27 at 16:54

They are trying to get at your knowledge of distributed systems. One of the tenets of distributed systems is unreliable clocks. You cannot count on clocks being in sync on different nodes, and you cannot reliably measure how out of sync they are.

There are algorithms to gain consensus on an order of events. One common way to agree on an order in practice is to push the events to Kafka. However, that's just an agreement on an order, there's really no way to ensure the agreed order is the actual real life order. In particular with Kafka, buffering for efficiency adversely impacts fairness.

I think most interviewers would be looking for you to acknowledge the impossibility of being perfect, lay out some reasons for that, then try to design something as fair as practical.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.