java – Online/offline status of users in real time


We have an internal project in the company where we study in our free time from the main projects. The project is a messenger with a video calling function. We take video communication and messaging (the ability to create and communicate in common channels) from a third-party SDK.

The client application is written natively for iOS and Android. Java backend.

The application has a standard contact list. And now the task has arisen to monitor the user's status in real time (ideally, implement the functionality like in telegram, such as "was online 5 hours ago") in the contact list, and by visiting his profile.

Please tell me which way to look? What needs to be done on the server, and what on the client?

After hours of googling, I found out that there is a technology like websocket and a tool like kafka. Can this be connected somehow?


You can do it in many different ways, depending on the desired set of features.

But, basically, you need to implement the following:

  1. A way to determine when a user is active.
  2. How to get status active/inactive

The simplest way, without sockets, would be:

  1. When a user performs some action that requires a connection to the server, on the server, when a request is received from the user, the time of arrival of the request is recorded.
  2. Now, by requesting information from the server about k-l user, you can also give the time recorded in n1.

This is the easiest to implement. However, this way you will not have the status "active right now" if you do not define "now" as прошло не более n времени с последнего обращения юзера к серверу . Those. if the user just launched the application and looks at the list of chats for hours without making network requests, it can be perceived as "inactive"

A more complicated way is to constantly notify the server about the user's status. For example, send a request to the server every n times while the application is running. This can be done with regular requests, or yes, supporting a socket connection, which in some cases may be preferable in terms of the number of requests to the server.

Scroll to Top