Live counter API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
docs update docs Nov 17, 2017
livecounter fix db reconnect Nov 16, 2017
server database url Nov 14, 2017
.gitignore initial server code Nov 14, 2017
COPYING license Nov 14, 2017 Update May 1, 2018 initial server code Nov 14, 2017
requirements.txt database url Nov 14, 2017

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.