'How Whatsapp, Facebook and Skype messaging works in the background?

What I'm trying to ask is:

  1. Whether these apps are relying on FCM/GCM (or any other type of) push notifications for syncing their data or are they using a socket connection in background through a service?
  2. If they are relying on push notifications then why they don't have any loss in receiving notifications (in background) while I miss 10-15% of notifications in busy hours.
  3. And if they are relying on a socket connection in background, then ain't this eat battery like a dinosaur?

What I have found is that if I force stop Messenger and Facebook I still receive messages but somewhat late than usual. Plus there is an option of 'Allow background activity' in Messenger, Facebook, Slack and Skype, which when I disable, I can't receive a notification at all. Interesting this is that WhatsApp don't have this kinda option in its app info and If I just force stop WhatsApp it simply stops showing me message notifications.



Solution 1:[1]

Whether these apps are relying on FCM/GCM (or any other type of) push notifications for syncing their data or are they using a socket connection in background through a service?

They must be relying on FCM.

If they are relying on push notifications then why they don't have any loss in receiving notifications (in background) while I miss 10-15% of notifications in busy hours.

They must be using FCM high priority which are reliably delivered in doze mode.

And if they are relying on a socket connection in background, then ain't this eat battery like a dinosaur?

They might not be running CPU intensive work.

Mobile applications like Whatsapp must be requesting permission to exempt them from Doze/battery saving and App standby mode. you can refer to my answer here for more details.

Solution 2:[2]

Adding on to Sagar answer.

1)Never show the notification from FCM notification payload unless required.

2)Once High priority FCM received you can do network operations for sometime and fetch data from server and then show up. If it fails whatsapp do puts ups with special msg. https://www.quora.com/Why-do-I-get-You-may-have-new-messages-notification-on-WhatsApp

3)use foreground service/ cpu lock tied with app icon momentarily till the data is fetched ,later close it.

PS:No whatsapp do not request for Battery Optimization. they probably reply on FCM high-priority message.

Solution 3:[3]

Well I have no idea what EXACTLY are they doing in background (maybe no one has), but lets take a look at the concept.

In distributed systems and web applications, no one usually goes for push notification system in background for their services to talk to each other. While it is possible, but these alive services have better options to choose such as publisher/subscriber pattern and technologies that bring this service for us (ex: reddis, MQ, Nats.io), they are high available and with no single point of failure, and the data is still synced over all server.

Your second question starts with an if which might have a false result. But lets say they do. You should never compare your "client to server connections and logic" with "Server to server connections and logic". What I mean is maybe they use Reddis pub/sub service, it doesn't mean their client should use same system to connect to server. It has a big cost to keep those servers connections alive while supporting big numbers of messages to sync.

And about third question. No, socket connections don't always drain battery. It really depends on how you use them. You can check for sockets idle modes too.

Also, systems like firebase might be still be able to send notifications when an application is not running or not connected to server. Happened to me a lot of times in Telegram, when government of Iran has blocked it but I could still receive notifications. Its whole other story, I think you can find more about it with a little search.

PS: Please avoid asking too many questions at once. thanks.

Solution 4:[4]

For services which exchanging frequently messages like messenger, WhatsApp, and WeChat etc there are message brokers (Activemq Artemis, RabbitMQ, Kafka etc) which is running on the server and having active stomp connection with each client app. This broker forward the message to the respective client as it received, and if the client is not online then it hold the message in memory untill the client become online. For further details that how a message broker works visit the official website of my favorite Activemq Artemis docs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Sep GH
Solution 4 Noor Khan