0

I was asked in an interview the following scenario:

  1. User1 looks at empty seats for a movie.
  2. User2 also looks at empty seats for a movie.
  3. Both select 'same seat' and hit submit.

1, What mechanisms would prevent same resource from being allocated to both ?

I answered, we will check the timestamp of each request on the app server. He said, what if load-balancer would redirect requests to different app servers ?

  1. Also asked if I could do anything on the DB-layer to prevent this ? I am weak on transactions and ACID but is it anything related to that ? Please explain ?
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132

1 Answers1

1

Just enforce the integrity rule that the same seat cannot be taken by two distinct persons at the same time. That should be just a matter of declaring the key {theatre#, seat#} (hard to tell without a given schema). The second user trying to get the seat will get an error message saying "seat not available". It could be explained explicitly and politely that this might be due to other people trying to do same.

Erwin Smout
  • 18,113
  • 4
  • 33
  • 52