One Backend Pattern Rarely Fits Everything
When building Tartila alongside its sibling community app Sambung Ngaji on top of a shared Go 1.26 + Fiber v2 backend, three distinct data workloads lived inside the same React 19 PWA:
- Strict identity & companion state: user accounts, JWT auth, and Tito & Tila mascot preferences stored exclusively inside Go's primary PostgreSQL database (
GET /api/v1/user/profile,PATCH /api/v1/user/mascot). Frontend clients are strictly forbidden from querying Supabaseusers. - Classroom & game economy tables: Ustadz room assignments and game progression schemas managed through structured Supabase Postgres migrations.
- Ephemeral live multiplayer arenas: Lobi Mabar tournament rooms and duels needing rapid frame updates (
phase_changed,question_result) even when mobile clients refresh mid-match.
Splitting relational truth from real-time arena state
Each persistence layer handles only the workload it excels at.
Dual-Publish Realtime With Authoritative Snapshots
In sambung-ngaji/backend/go/internal/realtime/ably.go, the Go backend broadcasts arena messages across room:{pin} and match:{sessionId} channels tagged with sequential eventSeq and stateVersion counters, while clients subscribe through useArenaChannel with canonical event aliases:
// Verified channel event aliasing & reconnect guard (tartila/src/hooks/useArenaChannel.ts)
const PHASE_EVENT_ALIASES: Record<string, string[]> = {
phase_changed: ["phase_changed", "match.phase_changed"],
"match.phase_changed": ["match.phase_changed", "phase_changed"],
};
export interface MascotUpdatePayload {
mascot_gender: "boy" | "girl";
equipped_accessory?: string | null;
avatar_variant?: number;
}Recovering Safely When Ably Drops a Frame
Because Ably broadcasts are ephemeral unless replay/history is queried, refreshing a browser tab mid-quiz can miss a phase_changed event. Our pattern solves this explicitly:
- Defer opening the Ably channel until the first authoritative HTTP
/statesnapshot resolves from Go Fiber. - Reconcile incoming frames against server-side
stateVersionso late pubsub packets never overwrite newer snapshot state. - Keep all identity mutations strictly gated behind Go Fiber JWT middleware.
Result in Production
Serving 116+ registered users, this split architecture allowed React 19 lazy-loaded game routes (6 2D mini-games built with Phaser & SVG/Framer Motion) and live multiplayer classrooms to stay responsive without duplicating user tables.