WhatsApp chose the Erlang language, designed to write scalable applications for troubleshooting. Erlang uses an abstraction called the Actor model for her concurrency - http://en.wikipedia.org/wiki/Actor_(programming_language) Instead of the traditional approach to shared memory, participants exchange messages by sending messages to each other. Actors, unlike threads, are designed for light weight. Actors can be on the same machine or on different machines, and paragraphs that transmit messages work for both. A simple WhatsApp implementation could be: Each user / device is presented as an actor. This subject is responsible for processing the user's incoming messages, how they are serialized to disk, messages that the user sends, and messages that the user receives. Suppose Alice and Bob are friends on WhatsApp. So, there is Alice's actor and Bob's actor.
Allows you to trace a number of messages coming back and forth:
Alice decides to inform Bob. The Alice phone establishes a connection with the WhatsApp server, and it is established that this connection is definitely connected to the Alice phone. Alice now sends the following message over TCP: "For Bob: a giant monster attacks the Golden Gate Bridge." One of the WhatsApp Fronts servers deserializes this message and delivers this message to Alice actor.
Alice, the actor decides to serialize this and store it in the file "Alice Sent Messages" stored in the replicated file system to prevent data loss due to the unpredictable corruption of monsters. Then Alice decides to pass this message to Bob to the actor, passing him the message "Msg1 from Alice: a giant monster is attacking the Golden Gate Bridge." Alice actor can repeat exponentially until Bob actor acknowledges receipt of the message.
Bob actor eventually receives a message from (2) and decides to save this message in a file called "Bob's Inbox." After he saves this message for a long time, Bob actor will confirm receipt of the message by sending Alice his message to the actor, saying: "I received Msg1." Alice actor can now stop trying again. Bob actor then checks to see if Bob's phone has an active connection to the server. This happens, and so Bob actor transmits this message to the device via TCP.
Bob sees this message and replies, "For Alice: Let them create giant robots to fight them." This now gets Bob the actor, as shown in step 1. Bob the actor repeats steps 2 and 3 to make sure that Alice ultimately gets an idea that will save humanity.
WhatsApp actually uses the XMPP protocol instead of the more advanced protocol that I outlined above, but you get the point.
alok srivastava Jul 26 '14 at 6:08 2014-07-26 06:08
source share