Amazon Interview Question
SDE-2sTeam: no
Country: India
Interview Type: In-Person
Highscalability.com is a good source.
Http question: use long polling from the client, so he can get notifications
Scalability: I would not necessarily say it's not scalable, there is not enough info given here to judge that. But the storage of pants in fields in classical relational manner is a bit hard to scale and unnecessary. You could just store a object as whole which contains the two set of pans with coordinates or the field as a whole. This can then be easily cached as a whole. That's easier to scale.
The password: it's bad practice to store it with encryption, store the hash and a seed, LS :-)
Highscalability.com is fun to read, then search for Google's Jeff Dean videos on YouTube, which I think is inspiring.
To start the session between two players, there should be a service which has a queue of players who are looking for other partner to play the game. This service will match two players based on their ratings and other parameters. Then it will call another service(say it SessionCreateService) to create the session between these two players and continue with matching other players in the queue.
When SessionCreateService will receive the requests , it will create a session between these two players by sending them response and finally GameService will handle the ongoing game.
You can long poll but for interview a better answer would be to use sockets such that you create a connection from client to server, and now server can push notification to you when events happens. This in contrast to long polling is less stressful on client as it does not use up as much resource polling.
Its hard to talk about the design here, but I'll give a general overview of how one might go about implementing this at a general level:
There are few details I haven't talked about, like what exactly does the gameModel look like?
Here is one way it could look :
There is obviously more to this, but thats a general overview. As for scaling, the default answer is to create multiple clusters of API which is gated by a load balancer. So when client request api endpoint, the load balancer intercepts the request, and delegates to a proper server which handles our restful request. And if we need to scale we can simply increase the number of clusters we have to handle more request.
- tnutty2k8 September 15, 2017I hope that was helpful to start.