Skip to content
All projects

Okey & 101 Multiplayer Game Engine: .NET 9 SignalR Backend

A highly concurrent, authoritative multiplayer game engine built under a commercial contract for a Unity-based Okey/101 board game, featuring real-time state synchronization.

Performance & metrics

  • Lock-free, thread-safe in-memory state resolution via ConcurrentDictionary for high-frequency actions (tile draw/discard) bypassing standard DB latency
  • Aggressive utilization of AsNoTracking() in Entity Framework Core for read-only queries, completely eliminating Change Tracker memory allocation overhead
  • Optimized Kestrel web server configuration tailored for Nginx reverse proxying, strictly handling X-Forwarded-For headers for network edge security

Why I built it

Developed as a commercial freelance contract, this project required a low-latency infrastructure for turn-based multiplayer board games where traditional HTTP request-response cycles fall short. To prevent client-side (Unity) manipulation and cheating, I needed to build a strictly authoritative server where all game logic, tile distribution, and win validations execute back-end. Modularity was crucial to support various game modes (Classic, 101, Bowl) without degrading into monolithic spaghetti code.

Architecture & decisions

The core runs on .NET 9.0, utilizing SignalR Hubs (SocialHub, TableHub) for full-duplex real-time communication. To completely bypass database I/O bottlenecks during high-frequency gameplay events, active game states (GameMatchState) are managed in RAM using a thread-safe ConcurrentDictionary. Diverse game rules are strictly decoupled via the Strategy Pattern implementing the IGameRuleHandler interface. Persistence (inventory, transactional ledgers, chat) is handled by PostgreSQL via Entity Framework Core, while heavy aggregate tasks like calculating leaderboards are offloaded to an asynchronous PeriodicTimer-based BackgroundService worker.

Key features

  • Production-ready economy and progression system enforcing transactional integrity across inventory, XP, and ledgers
  • Isolated matchmaking tables and clan/private chat rooms orchestrated via the SignalR Group API
  • Strategy Pattern implementation dynamically injecting diverse game rule constraints (Okey 101, Classic, 1v1) at runtime via DI
  • Server-side signaling relay infrastructure to support WebRTC-based in-game voice chat
  • Asynchronous background workers periodically computing and caching daily, weekly, and monthly leaderboards

Technical review

The most critical architectural decision in this commercial delivery was the strict decoupling of in-memory State Management from database Persistence. During active gameplay, tile pointers and turn sequences are resolved in memory in sub-milliseconds. Upon game completion (ClaimWin), the engine executes an atomic db.Database.BeginTransactionAsync() block to distribute XP, rewards, and bowl splits to PostgreSQL. This guarantees absolute ACID compliance, preventing any virtual currency duplication or ledger inconsistencies even during catastrophic server crashes.

Games & Simulation

The Burglar's Quest

A stealth-based game built in Unity, featuring a procedural generation engine that ensures unique spatial layouts and asset configurations per session.

  • C#
  • Unity

Games & Simulation

PTSD VR Simulation

A virtual reality simulation designed for PTSD awareness, featuring branching psychological narratives and real-time telemetry via Firebase.

  • C#
  • Unity
  • Firebase
  • +1

Games & Simulation

Private

Major project

BigScreenTogether: A Watch-Together Mod for Stardew Valley

A SMAPI mod that adds a 3×3 "Big Screen" furniture item and two cinemas to Stardew Valley. YouTube videos and subtitled anime episodes are drawn straight into the game without a browser; in multiplayer everyone watches the same second, and households can meet in the same room over Steam.

  • C#
  • SMAPI
  • Harmony
  • +6

Need something similar?

I can build a system like this for you, too.

Describe your project in a few sentences, and we'll work out the right approach and an estimated scope together.