What is WhatsApp's server architecture? - Quora
ERResearch's bookmarks 2016-08-14
Summary:
Components of their backend stack:
- Erlang
- FreeBSD
- Yaws, lighttpd
- PHP
- Custom patches to BEAM (BEAM is like Java’s JVM, but for Erlang)
- Custom XMPP
- Hosting may be in Softlayer
Brief description of how their Erlang services work:
- WhatsApp server is almost completely implemented in Erlang.
- Server systems that do the backend message routing are done in Erlang.
- Great achievement is that the number of active users is managed with a really small server footprint. Team consensus is that it is largely because of 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.
- WhatsApp server has started from ejabberd
- Ejabberd is a famous open source Jabber server written in Erlang.
- 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.
- 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.
- To handle 50 billion messages a day the focus is on making a reliable system that works. Monetization is something to look at later, it’s far far down the road.
- A primary gauge of system health is message queue length. 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. If one or more processes falls behind that is alerted on, which gives a pointer to the next bottleneck to attack.
- 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).
- Some code is usually pushed every day. Often, it’s multiple times a day, though in general peak traffic times are avoided. Erlang helps being aggressive in getting fixes and features into production. Hot-loading means updates can be pushed without restarts or traffic shifting. Mistakes can usually be undone very quickly, again by hot-loading. Systems tend to be much more loosely-coupled which makes it very easy to roll changes out incrementally.
- What protocol is used in Whatsapp app? SSL socket to the WhatsApp server pools. All messages are queued on the server until the client reconnects to retrieve the messages. 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). Messages are wiped from the server memory as soon as the client has accepted the message