Real-Time Online Presence Indicator: Implementation Guide

How to Build a Real-Time Presence Indicator for Your Website

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1284
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1240
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1031
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1104
  • image_website-_0.webp
    Website development for Red Pear
    553

How to Build a Real-Time Presence Indicator for Your Website

The Problem: Users See Avatars but Don't Know Who's Currently Online

We worked on a project — an online course platform with live webinars. Participants complained: "I write to the teacher in the chat, but they don't answer — turns out they're no longer online." It might seem trivial, but the lack of a real-time indicator reduced engagement by 15%. We implemented a presence indicator in two days. Now everyone sees a green dot and knows whom to ask a question right now. Over three years, we've deployed more than 50 such solutions for chats, courses, and corporate portals.

Heartbeat via HTTP Instead of WebSocket

We use heartbeat via HTTP — we send POST /api/presence/ping every 30 seconds. If there's no ping for 90 seconds, the user is considered offline. This approach is simpler than WebSocket and doesn't require a persistent connection. For most websites, it's sufficient. WebSocket provides accuracy down to a second but requires server infrastructure and a constant connection. The choice depends on the scenario: for a chat — WebSocket, for a course participant list — HTTP heartbeat.

Approach Accuracy Complexity When to Use
WebSocket/SSE ~1 second High Chat, collaborative editing
HTTP heartbeat ~60 seconds Low Profiles, participant lists
Last seen ~3 minutes Very low Privacy settings

Redis as the Ideal Storage for Presence

Redis is 10× faster than PostgreSQL in write speed for this task and automatically removes stale data without cron jobs. Each setex call creates a key with a TTL of 90 seconds. If the user stops pinging, the key disappears automatically. As noted in the Redis documentation, the SETEX command sets a key with automatic expiration. Below is a simplified implementation of our service:

class PresenceService { private const TTL = 90; public function markOnline(int $userId, string $context = 'global'): void { Redis::setex("presence:{$context}:{$userId}", self::TTL, now()->timestamp); $wasOnline = Redis::exists("presence_flag:{$context}:{$userId}"); if (!$wasOnline) { Redis::setex("presence_flag:{$context}:{$userId}", self::TTL + 10, 1); broadcast(new UserCameOnline($userId, $context)); } } public function markOffline(int $userId, string $context = 'global'): void { Redis::del("presence:{$context}:{$userId}"); Redis::del("presence_flag:{$context}:{$userId}"); broadcast(new UserWentOffline($userId, $context)); } public function getOnlineUsers(string $context = 'global'): array { $keys = Redis::keys("presence:{$context}:*"); return array_map(fn($k) => (int) last(explode(':', $k)), $keys); } public function isOnline(int $userId, string $context = 'global'): bool { return (bool) Redis::exists("presence:{$context}:{$userId}"); } } 
Explanation of the code The `$context` parameter allows splitting presence across sections: `chat_room:42`, `course:17`, `global`. The `setex` command sets a key that expires after TTL seconds. The `presence_flag` prevents duplicate broadcast events on each ping.

The $context parameter allows splitting presence across sections: chat_room:42, course:17, global.

Broadcast Events Synchronize Status

When the status changes, we broadcast UserCameOnline and UserWentOffline events. They contain only the user ID and context. The client receives the event and updates the green dot. For Laravel broadcast we use Pusher or Redis + Socket.IO. Example event:

class UserCameOnline implements ShouldBroadcast { public $userId; public $context; public function broadcastOn(): array { return [new PresenceChannel("presence.{$this->context}")]; } } 

The client subscribes to the channel via Laravel Echo and reacts to messages.

Why Choose a TTL of 90 Seconds?

The TTL should be three times the ping interval to compensate for brief connection losses. With a ping every 30 seconds, a TTL of 90 seconds covers three missed pings. If the connection drops for 40 seconds, the user doesn't go offline. A shorter TTL (e.g., 60 seconds) causes status flickering under unstable networks. A longer TTL (120+ seconds) delays the detection of user departure.

TTL Behavior
60 s flickers after missing 2 pings
90 s stable, reacts after 3 missed
120 s slow offline detection

Step-by-Step Instructions for Implementing a Heartbeat Ping

  1. Create a POST endpoint with authentication (e.g., Sanctum).
  2. In the PresenceService, implement markOnline/markOffline methods.
  3. On the client, send a ping on page load, then repeat every 30 seconds using setInterval.
  4. In the beforeunload handler, send an offline request via navigator.sendBeacon (see MDN documentation).
  5. On the server, upon receiving a ping, update the TTL. If no ping for 90 seconds, Redis deletes the key and an offline event is sent (implement a check on each ping or use a background task).

Common Mistakes When Implementing a Presence Indicator

  • Not using sendBeacon — when the tab is closed, the request doesn't go out, and the user stays online until TTL expires. Solution: use navigator.sendBeacon.
  • No context separation — all users see each other regardless of section. Solution: pass context in every ping.
  • TTL too short — the user flickers (online/offline) under unstable connections. We recommend TTL = 3 times the ping interval.

What's Included in the Work

  • Development of the heartbeat endpoint and Redis service
  • Configuration of broadcast events UserCameOnline, UserWentOffline
  • Implementation of the indicator in the UI (dot / badge)
  • API and integration documentation
  • Team instruction for further maintenance

Our engineers have 5+ years of experience with Laravel and Vue/React. Over 3 years, we have implemented more than 50 similar solutions for chats, courses, and corporate portals. Our proven track record guarantees reliable implementation.

Timelines and Cost

  • Heartbeat ping + Redis TTL + indicator: 1–2 days (approx. $1,500–$3,000)
  • Broadcast on status change: 1 day (approx. $1,000)
  • Presence Channels via Laravel Echo: 1 day (approx. $1,000)
  • Last seen: 0.5 day (approx. $500)
  • Privacy settings: +0.5 day (approx. $500)

Cost is calculated individually based on complexity. Contact us — we'll evaluate your project within one business day. Get a consultation for your project — our engineers will help select the optimal solution. We offer a 100% satisfaction guarantee.