So let's take the Facebook Messenger app for example. When you send a message it instantly gets sent to the other user you are writing to.I believe they use some kind of WebSockets to send these messages (correct me if I'm wrong).
But when the other user closes the app, does he still receive the message? Does Messenger always keep Websocket connections alive? Because if they don't, how comes the other user still receives a notification saying he got a new message?

I don't understand a lot about this technology so I might be really far away from reality.

  • 2
    The messages are not sent directly but centrally stored. The apps talk to the central server, or get push-notifications from the underlying operating system. Apr 2, 2021 at 4:23
  • They are using something like activeMQ . Apr 2, 2021 at 8:22
  • Just so you can research the right topics, your interpretation of two users being directly connected is called "peer to peer". You'll find plenty of information online on that topic.
    – Flater
    Apr 2, 2021 at 11:23

2 Answers 2


There is no one answer to this, because over the years there have been many, many different chat programs and protocols, but there are a few basic ways of building it:

  • Store and forward, with polling. This is the most basic setup: Alice sends a message addressed to Bob to a central server, which stores it in Bob's inbox; Bob's client periodically "polls" the server to ask if there are new messages. This is how e-mail works, for instance, with the extra detail that Alice can send to one central server and it will relay it to another which hosts Bob's inbox.
  • Store and forward, with push delivery. This is a common enhancement to the above, where the central server can actively "push" messages to Bob's client, rather than waiting for it to poll. This can be achieved using "long polling", where the Bob's client essentially says "Do you have any messages? Don't reply until the answer is yes"; or it can use a feature of the underlying network connection, such as a sending a special SMS to a mobile phone.
  • Peer-to-peer. This is basically what you describe in the question: the service helps Alice and Bob establish a direct network connection between them, and messages can be sent only while the connection is open. When Bob logs in, the central server can tell Alice that he's available to chat, and often includes a custom "status" message which Bob can set. If e-mail is like delivering a letter, peer-to-peer chat is like a phone call; in fact, a major use case is voice and video chat, where going via a central server might add latency without much gain.
  • Any combination of the above. A service built primarily on peer-to-peer might offer an offline delivery system - a bit like having a voicemail service attached to your phone line. A store-and-forward service may offer both polling and push delivery, depending on preference or network capabilities.

Primarily, they use the Apple (APNS) or Google (FCM) push notification service.

This is the primary mechanism because it's the only one supported by the operating system iOS / Android that will efficiently wake up the target app when the message is received.

see https://stackoverflow.com/a/63443012/887092

The Push Notification itself can include data, but when it wakes the app, the app might then retrieve more data from one or more APIs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.