Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



27 Commits

Repository files navigation

Live Counter

Django implementation and API for a counter with live updates. POST to increment. GET to listen for updates (server-sent events).

This project uses Fastly and Fanout for high scale. Essentially, Fastly caches the current counter values, and counter updates are pushed through Fanout, greatly reducing load on the Django app itself in order to serve lots of clients. Technical background in this article.

There is a public instance available at


Install dependencies:

virtualenv venv
. venv/bin/activate
pip install -r requirements.txt

Also be sure you have Redis installed, which the main server process uses to communicate with the publisher process.

Ensure you have accounts with Fastly and Fanout Cloud, and set up the same domain in both systems. Additionally, create a Fastly API key. Then, create a .env file with the following environment variables:


You can also set DATABASE_URL to point to a database. If not set, sqlite will be used.

Create database tables:

python migrate

Create a counter object:

from livecounter.models import Counter
c = Counter(name='foo')


Run the main server (either using python runserver or a webserver with server/

Also, run the publisher command (python publisher, either in another terminal or as a background service).

Point the domain CNAME at Fanout Cloud. Configure the Fanout Cloud domain to proxy traffic to Fastly. Configure Fastly to point traffic to this server.