DEV Community

masterai-top
masterai-top

Posted on

Decoding Texas Hold'em Server Architecture: How to Support 10,000 Concurrent Users with Unity + C++

An open-source, production-ready solution for high-concurrency poker game servers.

When I first started building a Texas Hold'em backend, I found plenty of tutorials showing how to evaluate poker hands or create a single-player game. But finding a production-ready, high-concurrency architecture that could support clubs, agents, and MTT/SNG tournaments? Almost impossible.

Most resources are either:

  • Too simple: Single-threaded, blocking I/O, can't handle >100 players.
  • Too commercial: Closed-source, expensive licensing, no transparency.

That's why I built [Project Name]. After [X months/years] of development, I'm open-sourcing a complete Texas Hold'em solution:

  • Client: Unity (cross-platform, smooth UI/UX)
  • Server: Modern C++17/20 (high-performance, low-latency)
  • Concurrency Model: [your model, e.g., Reactor + thread pool / Actor model / Coroutines]
  • Protocol: [e.g., Custom TCP + Protobuf / WebSocket + JSON]

In this article, I'll walk you through the critical architectural decisions that allow this system to handle 10,000+ concurrent players on a single server cluster.

🔗 Full source code: https://github.com/masterai-top/TexasHoldem-Poker-Complete-Solution

Section 1: Why Unity + C++?
Many game engines exist, but the Unity + C++ combination offers unique advantages for card games:

Client-side (Unity)

  • Cross-platform: One codebase for Windows, macOS, iOS, Android.
  • Rich asset store: UI frameworks, particle effects, animations ready to use.
  • C# scripting for game logic, easy to integrate with native C++ plugins.

Server-side (C++)

  • Deterministic performance: No GC pauses, predictable latency.
  • Fine-grained memory control: Pool allocators for game rooms, players, cards.
  • Battle-tested networking libraries: [e.g., Boost.Asio / libuv / uvpp].

Communication Bridge

  • [Describe your approach: e.g., Custom TCP protocol with message framing]
  • [Or: WebSocket + binary encoding for browser-based WebGL clients]

The client is lightweight (only responsible for rendering and input), while the server handles all critical logic: dealing, hand evaluation, pot management, and anti-cheat validation.
Section 2: Core Server Architecture – Handling 10k Concurrent Users
The heart of any poker server is the room/table management system. Here's how we achieve high concurrency:

2.1 Room/Table Manager

  • Pre-allocated memory pool for [e.g., 10,000] table objects to avoid dynamic allocation during gameplay.
  • Each table runs as a lightweight state machine: Waiting → Preflop → Flop → Turn → River → Showdown → Settled.
  • No per-table threads! Using [e.g., a single event loop / thread pool of N workers], one server instance can handle [e.g., 5,000] tables.

2.2 Networking Model
We use [choose your model]:

  • Option A (Reactor): One event loop (epoll/IOCP) dispatches messages to worker threads.
  • Option B (Coroutines): C++20 coroutines for sequential-looking async code.

Pseudocode example:


cpp
class TableManager {
public:
    void ProcessMessage(PlayerID pid, const Message& msg) {
        auto table_id = player_to_table_[pid];
        tables_[table_id]->HandleInput(pid, msg);
    }
private:
    std::vector<Table> tables_;  // Pre-allocated
    std::unordered_map<PlayerID, TableID> player_to_table_;
};

2.3 State Synchronization

Only delta updates are sent to clients (e.g., "Player A raised by 50 chips").

Full state snapshots are sent only when a player joins or reconnects.

Typical bandwidth: [e.g., < 5KB/s per player].

### Section 3: Hand Evaluation – Ultra-Fast 7-Card Poker Evaluator
Performance is critical here. The naive approach (enumerating all 21 combinations of 5 cards from 7) is too slow for 10,000 tables.

Our solution: [Choose one]

Option A – Prime Number Method:

Map each card to a unique prime number (2,3,5,7,11...).

Multiply primes of 5 cards → unique product that maps to a hand strength value.

Pre-compute lookup table of size [e.g., 10,000] entries.

Option B – Bitmask + Perfect Hashing:

Each card represented as a bit in a 64-bit integer (2 bits for suit? 4 bits for rank?).

Use pre-computed rank tables from [e.g., Cactus Kev's evaluator / PokerStove].

Performance result: [e.g., 0.5 microseconds per evaluation]

Code snippet (simplified):
uint32_t EvaluateHand(uint64_t cards) {
    // Use a pre-computed hash table
    return hand_rank_table[Hash(cards)];
}

**### Section 4: Anti-Cheat & Fairness**
Since poker involves real money/club points, security is paramount:

Server-side authority: Clients only send actions (fold/call/raise). The server:

Deals cards (true random number generator, e.g., std::random_device + cryptographic seed)

Evaluates winners

Manages chip movement

Validation layer: Every client action is re-validated:

Is the player at this table?

Does the player have enough chips?

Is it this player's turn?

Audit trail: All game actions logged in [MySQL/PostgreSQL/ClickHouse] for replay and anomaly detection.

Bot detection (optional): [Describe any anti-bot measures, e.g., behavior analysis, CAPTCHA on login].

**### Section 5: Real-World Performance & Demo**
We've tested this architecture on [e.g., c5.4xlarge AWS instances with 16 vCPUs / 32GB RAM].

Benchmark results (single server instance):

Max concurrent tables: [e.g., 8,000]

Max concurrent players: [e.g., 60,000 (8-player tables)]

Average latency (p99): [e.g., 25ms]

CPU usage at full load: [e.g., 70%]

Demo available: You can try a live demo at [your demo link].

The complete source code includes:

Unity client full project

C++ server with CMake build system

Deployment scripts (Docker + Kubernetes ready)

Database schema (MySQL/Redis)

### Conclusion & Call-to-Action
This architecture represents [X months/years] of production testing and refinement. It's not just a toy project – it's actively running on [e.g., 3 commercial sites] handling [e.g., $X daily / X players daily].

If you're building:

A social poker game

A club/league management system

A poker training platform

...this codebase can save you months of development time.

🔗 GitHub Repository: https://github.com/masterai-top/TexasHoldem-Poker-Complete-Solution

⭐ Star the repo if you find it useful – it helps other developers discover this resource.

Questions or feedback? Open an Issue on GitHub or reach out via [Twitter/Email/Discord link].

Happy coding!

### Tags for Medium

Unity, Cpp, Game Development, Poker, System Architecture, Backend, Networking, Open Source, Software Engineering, Concurrency

Enter fullscreen mode Exit fullscreen mode

Top comments (0)