One of the WhatsApp front end server deserializes this message and delivers this message to the actor called Alice.Īlice the actor decides to serialize this and store it in a file called "Alice's Sent Messages", stored on a replicated file system to prevent data loss due to unpredictable monster rampage. Alice now sends via TCP the following message: "For Bob: A giant monster is attacking the Golden Gate Bridge". Alice's phone establishes a connection to the WhatsApp server and it is established that this connection is definitely from Alice's phone.
Let's trace a series of messages flowing back and forth:Īlice decides to message Bob. So there is an an Alice actor and a Bob actor. Let's assume that Alice and Bob are friends on WhatsApp. This actor is responsible for handling the inbox of the user, how it gets serialized to disk, the messages that the user sends and the messages that the user receives. A simple implementation of WhatsApp could be:Įach user/device is represented as an actor. Actors could be on the same machine or on different machines and the message passing abstractions works for both. Actors unlike threads are designed to be lightweight. Erlang uses an abstraction called the Actor model for it's concurrency - (programming_language) Instead of the more traditional shared memory approach, actors communicate by sending each other messages. WhatsApp has chosen Erlang a language built for writing scalable applications that are designed to withstand errors. This also means that registering a new device will invalidate the key on the old device. (this "permanent" key is stored on the device). This key is used as "password" for all future calls. Based on the pin number the app then request a unique key from WhatsApp. WhatsApp will then send a SMS to the indicated phone number (this means the WhatsApp client no longer needs to run on the same phone). WhatsApp now uses a general request from the app to send a unique 5 digit PIN.
How does the registration process work internally in Whatsapp? WhatsApp used to create a username/password based on the phone IMEI number. Messages are wiped from the server memory as soon as the client has accepted the message The successful retrieval of a message is sent back to the whatsapp server which forwards this status back to the original sender (which will see that as a "checkmark" icon next to the message).
All messages are queued on the server until the client reconnects to retrieve the messages. What protocol is used in Whatsapp app? SSL socket to the WhatsApp server pools. Systems tend to be much more loosely-coupled which makes it very easy to roll changes out incrementally. Mistakes can usually be undone very quickly, again by hot-loading. Hot-loading means updates can be pushed without restarts or traffic shifting. Erlang helps being aggressive in getting fixes and features into production. Often, it’s multiple times a day, though in general peak traffic times are avoided. Multimedia messages are sent by uploading the image, audio or video to be sent to an HTTP server and then sending a link to the content along with its Base64 encoded thumbnail (if applicable). If one or more processes falls behind that is alerted on, which gives a pointer to the next bottleneck to attack. The message queue length of all the processes on a node is constantly monitored and an alert is sent out if they accumulate backlog beyond a preset threshold. Monetization is something to look at later, it’s far far down the road.Ī primary gauge of system health is message queue length. To handle 50 billion messages a day the focus is on making a reliable system that works.
The next few years were spent re-writing and modifying quite a few parts of ejabberd, including switching from XMPP to internally developed protocol, restructuring the code base and redesigning some core components, and making lots of important modifications to Erlang VM to optimize server performance. Originally chosen because its open, had great reviews by developers, ease of start and the promise of Erlang’s long term suitability for large communication system. WhatsApp server has started from ejabberdĮjabberd is a famous open source Jabber server written in Erlang. Interesting to note Facebook Chat was written in Erlang in 2009, but they went away from it because it was hard to find qualified programmers. Team consensus is that it is largely because of Erlang.
Great achievement is that the number of active users is managed with a really small server footprint. Server systems that do the backend message routing are done in Erlang. WhatsApp server is almost completely implemented in Erlang. Here is the general explanation from the link The WhatsApp Architecture Facebook Bought For $19 Billion explains the architecture involved in design of whatsapp.