Key takeaways
- Store each ball as an event with a client-generated id and a unique index; a retried request with the same id is ignored, so a ball can never be counted twice.
- Calculate scorecards, partnerships, points tables and careers from the events instead of editing running totals.
- Undo means removing the last event and recalculating – not subtracting numbers by hand.
- Keep match rules (overs, bowler limits, extras) on the match and record rule changes as events too.
- Net run rate uses overs as balls ÷ 6, and a team that is all out is charged its full quota of overs.
In this article
The cricket module in BAGALEPA started from a very local problem. Villages in our samaj play gully matches and full tournaments every season, but scores were written in notebooks or typed into WhatsApp groups and lost after the match. Players had no record of their runs and wickets, and organisers built points tables by hand.
Building a scoring app sounds simple until you watch a real match: one scorer, one phone, a ground at the edge of a village with two bars of mobile data, and hundreds of people following from other villages. This article explains the design that made scoring reliable in those conditions.
The core decision: every ball is an event
The first version of many scoring apps keeps a running total – runs, wickets, overs – and updates it after each ball. That breaks in three common situations: a request is retried on a weak network, the scorer presses undo, or the umpire changes a decision two balls later. Each one needs careful subtraction, and sooner or later the totals drift.
We store each delivery as an event instead:
- a unique ball id created on the scorer's phone (unique per match in the database),
- innings, over and ball position,
- striker, non-striker and bowler,
- runs off the bat, extras (wide, no-ball, bye, leg-bye) and their runs,
- wicket type and the batter out, if any.
The scorecard, batting and bowling figures, partnerships, fall of wickets and run-rate charts are all calculated from the list of events. Nothing is edited by hand, so there is nothing to drift.
Weak internet without double counting
When the scorer taps "4", the app creates the ball with its own id and posts it to the API. If the request times out on a weak network, the app simply sends it again with the same ball id.
On the server, the ball id is unique within the match. If a retry arrives for a ball that was already saved – because the first request reached the server but the reply was lost – the server returns the saved ball and does nothing else. This idempotency is what makes the queue safe: the scorer can keep scoring through a dead zone, and every ball is counted exactly once when the network comes back.
Two more guards protect the score when several people are involved:
- Expected sequence. Every tap also says which ball number it expects to follow. If two devices try to score the same match, the second one is rejected instead of silently overwriting the first.
- One scorer at a time. A scoring lock with a heartbeat makes sure only one phone is scoring. If the scorer's battery dies, an organiser can take over and continue from the last saved ball.
Undo, corrections and changing rules
Undo removes the last event and the score is recalculated. Because every number comes from the events, undoing a wicket automatically restores the batter, the bowler's figures and the fall-of-wicket list.
Village matches also change their rules mid-game more often than you might think: the bowler over limit is relaxed, a wide stops counting as a run, or an over is discontinued because the bowler is injured. We store the match rules on the match itself – overs, players per side, bowler limit or no limit, runs for wides and no-balls, free hit, last-man-stands – and record each rule change with the ball from which it applies. Earlier overs stay valid, and checks such as "this bowler has finished his overs" use the rule that was active at that moment. A discontinued over is recorded explicitly, with the organiser choosing whether its runs count.
Live updates for hundreds of viewers
After a ball is saved, the API emits the updated summary to a Socket.IO room for that match. Spectators in the Match Center see the score, the current over and the commentary line within a second. The same pattern we used for kitchen screens in Parozo applies here: the database is the source of truth, the socket only makes it faster. A viewer whose phone reconnects reloads the latest scorecard from the API instead of trying to replay missed messages.
Each ball sends one small message of a few hundred bytes to the match room, and no database work happens per viewer. The heavier views – full scorecard and commentary – are fetched only when that tab is opened, from an in-memory cache, and identical requests arriving together share a single database query. That keeps the server calm during a final and keeps mobile data use low for people watching on prepaid plans.
Points tables and net run rate
Tournaments support leagues, groups, knockouts and IPL-style playoffs. The points table is recalculated from finished matches, and the tie-breaker everyone argues about is net run rate (NRR):
NRR = (total runs scored / total overs faced)
- (total runs conceded / total overs bowled)
Two details cause most NRR bugs:
- Overs are not decimals. 14.2 overs means 14 overs and 2 balls, which is 14 + 2/6 = 14.333 overs, not 14.2. We store balls and divide by six only when calculating.
- All out counts the full quota. If a team is bowled out in 12.3 overs of a 16-over match, its overs faced for NRR are 16. Revised targets and shortened matches need their own handling, so the match stores the overs quota that actually applied.
Player careers and awards
Because every ball names the batter and bowler, career statistics come for free: matches, runs, average, strike rate, wickets, economy and best figures, across gully matches and tournaments. Leaderboards such as the Orange Cap and Purple Cap, Player of the Match and MVP awards are calculated from the same events, so a correction in one match flows into every table automatically.
Sharing and going live
A score that nobody sees does not help a tournament. Every match and tournament has a share link with a preview image of the current score, and it opens the Match Center directly in the app when it is installed – we explain how in our article on WhatsApp share links that open the app. Organisers can also stream to YouTube with a live score strip, using the same match data.
What we would tell anyone building a scoring app
| Do | Avoid |
|---|---|
| Store balls as events with ids | Editing running totals |
| Retry with the same ball id | Blocking the scorer on network errors |
| One scorer lock with takeover | Two phones scoring the same match |
| Store balls, divide by six only for display | Saving overs as decimals |
| Rules on the match, changes as events | Global settings for every match |
| Recalculate tables from finished matches | Adding points by hand |
Village cricket deserves the same quality of scoring as televised matches – and with a careful data model, a single phone is enough. If you organise a league or want a sports app of your own, talk to RelieveX Labs.
Case studies mentioned in this article
Frequently asked questions
What happens if the scorer's phone loses internet during a match?
The app sends the ball again with the same id when the connection returns. Because the server ignores a ball id it has already saved for that match, retries can never add a ball twice.
How is net run rate calculated?
Net run rate is runs scored divided by overs faced, minus runs conceded divided by overs bowled, across all matches. Overs are converted to balls ÷ 6 (14.2 overs = 14 and 2/6 overs), and a side that is bowled out is counted as having faced its full quota of overs.
Can rules be changed after a match has started?
Yes. In BAGALEPA, rule changes such as the bowler over limit are stored on the match with the ball from which they apply, so earlier overs remain valid and later checks use the new rule.
How do spectators see the score live?
Every saved ball is pushed to a Socket.IO room for that match. Spectators' screens update within a second, and if a screen reconnects it reloads the latest scorecard from the API.
References & further reading

About the author
Priyank Patel
Founder of RelieveX Labs / RelieveX - IT Solutions · 3+ years experience
Priyank Patel is a Full Stack MERN Developer and Founder of RelieveX Labs, specializing in high-performance web applications, scalable mobile apps, and SEO-driven digital solutions. With expertise in React, Next.js, Node.js, MongoDB, and React Native, he helps businesses build powerful, conversion-focused digital products.
View profile & projects





