๐—ฆ๐˜๐—ฟ๐—ฒ๐—ฎ๐—บ๐—ถ๐—ป๐—ด ๐—Ÿ๐—ถ๐˜ƒ๐—ฒ ๐—ฉ๐—ถ๐—ฒ๐˜„๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—ฃ๐—›๐—ฃ ๐Ÿด.๐Ÿฐ ๐—ฎ๐—ป๐—ฑ ๐—ฆ๐—ฆ๐—˜

Your viral video goes from 4,000 to 1 million views. Your frontend uses polling. This creates 600 requests per second. Your server struggles.

Polling is the wrong tool for live numbers. The server knows the value. It should push the value to you.

Use Server-Sent Events (SSE). SSE is a one-way stream from server to browser.

Why SSE works:

Your stack needs a fast database. Use SQLite in WAL mode. This lets readers and writers work at the same time.

Do not update the database on every hit. This slows the system. Instead, buffer updates in memory. Flush them to the database once per second.

Buffering often breaks SSE. You must disable it in three places:

Use a heartbeat every 15 seconds. This keeps the connection open through Cloudflare.

Scale your app in tiers:

One Go process reads the database once. It sends the update to thousands of users. This saves your server from crashing.

The results:

Source: https://dev.to/ahmet_gedik778845/streaming-live-video-view-counts-with-server-sent-events-in-php-84-3iam