<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Vainu Engineering]]></title><description><![CDATA[Vainu Engineering]]></description><link>https://vainu.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 23:30:48 GMT</lastBuildDate><atom:link href="https://vainu.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[What we learned building offline-first attendance for school buses in India]]></title><description><![CDATA[How Vainu records school bus attendance with no signal: trip packages, append-only events, sync order, on-phone face matching and stale GPS.]]></description><link>https://vainu.hashnode.dev/what-we-learned-building-offline-first-attendance-for-school-buses-in-india</link><guid isPermaLink="true">https://vainu.hashnode.dev/what-we-learned-building-offline-first-attendance-for-school-buses-in-india</guid><category><![CDATA[React Native]]></category><category><![CDATA[Android]]></category><category><![CDATA[offline first]]></category><dc:creator><![CDATA[Kris Garg]]></dc:creator><pubDate>Wed, 02 Dec 2026 08:43:08 GMT</pubDate><content:encoded><![CDATA[<p><em>Originally published on</em> <a href="https://dev.to/krisgarg/what-we-learned-building-offline-first-attendance-for-school-buses-in-india-150m"><em>DEV</em></a><em>.</em></p>
<p>A school bus in India spends a good part of its route in places with no mobile signal: flyovers, outskirts, basements of school buildings. If an app records which children got on and off that bus, "no signal" cannot mean "no record". We build <a href="https://www.vainu.in">Vainu</a>, school bus tracking and attendance that runs on the conductor's Android phone, and this post covers the decisions that mattered most for making it work offline. None of it is specific to buses; it applies to any field app where a person records events away from a network.</p>
<h2>1. Download the whole trip before it starts</h2>
<p>When a conductor starts a trip, the phone downloads a <strong>trip package</strong>: the stops with their geofences, the children expected on this trip and their stops, and (for children whose guardians consented) the face templates needed to recognise them. It is encrypted on the device and comes with a <strong>lease</strong> that has an expiry time.</p>
<p>Two things follow from this:</p>
<ul>
<li>Everything the conductor needs during the trip is already on the phone. The app never has to ask the server "who is this child?" mid-route.</li>
<li>The lease gives the server a way to say "this trip is no longer yours" (another phone took it over, the school cancelled it) without the phone having to be online at that moment. When the phone next syncs and the server refuses its events with a trip-gone code, the phone flags the trip and closes it locally instead of carrying on recording into a trip nobody will accept.</li>
</ul>
<h2>2. Record events, not state</h2>
<p>The phone does not store "Asha is on the bus". It stores an append-only list of events: boarded at stop 3 at 07:42, dropped at school at 08:15. The current state of each child is a projection of those events, computed the same way on the phone and on the server.</p>
<p>Each event gets an immutable UUID and a per-trip sequence number when it is created. That buys you three things:</p>
<ul>
<li><strong>Retries are free.</strong> If a sync request times out halfway, the phone sends the same events again and the server answers with the original result. Nothing is double-counted.</li>
<li><strong>Gaps are visible.</strong> A server that receives sequence 1, 2, 4 knows something is missing and can wait rather than draw the wrong conclusion.</li>
<li><strong>Corrections are history, not edits.</strong> A wrong record is corrected by a new event, so the audit log shows both. For a school answering a parent's question, "what happened" matters as much as "what is true now".</li>
</ul>
<h2>3. Sync in an order that keeps the server's checks honest</h2>
<p>The outbox does not send everything at once. It goes in a fixed order:</p>
<ol>
<li>attendance events, in sequence order</li>
<li>exceptions (a child who was not at the stop, a wrong bus)</li>
<li>trip completion, <strong>only after that trip's attendance has fully drained</strong></li>
<li>photos</li>
<li>GPS points</li>
</ol>
<p>The third step matters most. At the end of a trip the server checks that every child who boarded was dropped off, and raises an alert if not. If the "trip ended" message arrived before the last few drop-offs (because they were recorded in a dead zone and are still queued), the server would raise a false "child unaccounted for" alert. Holding the completion until the attendance queue for that trip is empty prevents that.</p>
<p>GPS goes last because it is the most voluminous and the least urgent once the trip is over; a parent cares far more that the drop-off record arrives than that the 400th location point does.</p>
<h2>4. Face recognition suggests, a person confirms</h2>
<p>Face matching runs on the phone against the templates in the trip package only. That is a 1:N search over perhaps 40 children, not over every child in the school, which makes it both faster and much less likely to confuse two children.</p>
<p>Even so, the match is a suggestion. The engine returns one of <code>match</code>, <code>no_match</code> or <code>uncertain</code>, and a <code>match</code> also has to beat the second-best child by a margin; two similar-looking siblings on the same bus produce an <code>uncertain</code>, not a guess. The conductor then confirms the suggested name or picks the child from the list. Nothing is recorded until a person taps confirm.</p>
<p>The event stores what the engine observed (the score and the result), never the camera frame or the template. Face data stays on the trip's phone.</p>
<h2>5. Android's cached location will lie to you</h2>
<p>When you start location tracking on Android, the first fix delivered is often the cached last-known position. It can be hours old and kilometres away: where the phone was last night, not where the bus is now. Draw that on a parent's map and they see the bus teleport.</p>
<p>The fix is small. Record the moment tracking started, and drop any fix with a timestamp before it. Keep fixes that arrive late in a batch (Android delivers them in bursts when the phone has been dozing): they were taken during the trip, they just arrived late.</p>
<pre><code class="language-ts">export function fixesSince&lt;T extends { timestamp: number }&gt;(
  fixes: readonly T[],
  trackingSinceMs: number | null,
): T[] {
  if (trackingSinceMs === null || !Number.isFinite(trackingSinceMs)) return [...fixes];
  return fixes.filter((f) =&gt; Number.isFinite(f.timestamp) &amp;&amp; f.timestamp &gt;= trackingSinceMs);
}
</code></pre>
<h2>6. Tell people what you know and when you knew it</h2>
<p>Offline-first is not only a storage problem. If the bus's last position is four minutes old, the parent app says so next to the dot. If a boarding record has been taken on the phone but has not reached the school yet, the conductor's screen marks it as waiting to sync, and the parent is only notified once the school actually has the record. A stale fact shown as stale is useful; a stale fact shown as live is worse than nothing.</p>
<h2>What we would tell someone starting out</h2>
<ul>
<li>Decide what the device must be able to do with zero network, and ship that data to the device before it is needed.</li>
<li>Make every write an immutable event with a client-generated ID, and make the server idempotent on that ID.</li>
<li>Think about the order in which queued data arrives, especially where the server draws conclusions from absence.</li>
<li>Keep a human in the loop wherever a wrong automatic decision would be hard to undo.</li>
</ul>
<p>If you run school transport in India, or are building something similar, I would like to hear how you handle the same problems. Vainu is at <a href="https://www.vainu.in">vainu.in</a>.</p>
]]></content:encoded></item></channel></rss>