← Stories

How One Shared Number Stays Honest

By Rehan Sayyed, SRT Corporates · Published

Click With The World has one number that everyone can change. Anyone, anywhere, without an account, can open the site and make the total go up. That is the whole idea, and it is also the whole problem: a number anyone can change is a number someone will try to change by a million at once.

This article explains the rules that sit between your browser and that number.

The database checks every write

The total is stored in Google's Firebase Realtime Database, and your browser talks to it directly. No server of ours sits in the middle deciding what to accept. Instead, the database checks every write against a short list of rules before saving anything. If a write breaks a rule, it is rejected and the number does not move.

The starting point is that nothing may be written anywhere:

".write": false

Every exception is listed one by one: the world total, each country's total, today's total, the milestone dates, the short Live Clicks list, and a per-browser timestamp. Anything else is refused.

Rule one: the new value is the old value plus one

This is the rule for the world total:

newData.isNumber() && newData.val() == (data.exists() ? data.val() : 0) + 1

In words: the value being saved must be a number, and it must be exactly one more than the value already there. Not "greater than". Exactly one more.

That single line rules out most mischief. Nobody's browser can set the total to a billion, lower it, reset it to zero, or replace it with a word. Each accepted write is one step. The same rule applies to every country's total and to the daily total.

Rule two: nothing can be deleted

A second condition sits beside the first on every counter:

".write": "newData.exists()"

To the database, deleting a value means writing "nothing" in its place. This rule says the new data must exist, so a delete is refused.

Rule three: the parts of a click must agree

A click is not one write. It changes several things together: the world total, your country's total, today's total and the Live Clicks list. They are sent as one update, and the database treats one update as all-or-nothing. If any part breaks a rule, none of it is saved.

The rules use this. Today's total may only go up by one if the world total goes up by one in the same update. The same holds for a new entry in Live Clicks. So the daily figure cannot run ahead of the total, and the list cannot fill with clicks that never happened.

Timing is checked too. The site records when each browser last clicked, and the rules reject a new time less than 800 milliseconds after the previous one. That timestamp travels in the same update as the click, so a click sent too quickly is refused whole.

Rule four: a milestone date is written once

When the total first reaches a number on the milestone ladder, from 1,000 up to 100,000,000, the date is saved. Three conditions apply:

Two people clicking at the same moment

Suppose two people both see 41 and both send 42. One click would be lost. So the site never sends a number. It sends an instruction, "add one", and the database applies it to whatever the value is at that instant. The rule then checks the result. Two clicks at the same moment become 42 and 43.

What the rules do not do

Rules check the shape of a write: is it a number, and is it one more than before. They cannot see who is sending it. Telling the real site apart from a script is a separate job, done by Firebase App Check, which is the subject of the next article.

The rules also apply to visitors, not to us. As the Terms of Use say, we can correct the counts if we find clicks that were added by automation.

No set of rules is foolproof. What these give is a narrow door: the only thing a visitor's browser can do to the number is add one to it. The full rules file is in the project's public repository.