Skip to content

Networking — Getting Started

The mesh networking feature allows your services to discover each other and form a cluster. Let's start simple: three nodes.

How It Works

Nodes connect to seed nodes to discover the cluster. Once connected, they learn about all other peers and form a mesh.

Node A (seed: 10.0.0.1:10000) ←→ Node B

   Node C

Step 1: Start a Seed Node

cpp
#include <framework.hpp>
#include <iostream>


using namespace framework;

int main() {
    configuration config;
    config.ports_.node_port_.store(10000);

    framework::app app(config);
    app.run_mesh();

    std::cout << "Seed node listening on port " << 10000 << std::endl;
    app.run();
    return 0;
}

Step 2: Start Regular Nodes

cpp
#include <framework.hpp>
#include <iostream>


using namespace framework;

int main() {
    configuration config;
    config.ports_.node_port_.store(10001);
    config.seed_.enabled_.store(true);
    config.seed_.host_.store(std::make_shared<const std::string>("10.0.0.1"));
    config.seed_.node_port_.store(10000);

    framework::app app(config);
    app.run_mesh();

    std::cout << "Node starting, connecting to 10.0.0.1:10000" << std::endl;
    app.run();
    return 0;
}

Step 3: Verify

Run each node and watch the logs. You should see connection messages:

[service] Connected to peer 10.0.0.1:10000
[service] Registered peer a1b2c3d4-... (10.0.0.1:10000)

What's Next

Once connected, cache events, Pub/Sub messages, and state changes propagate across all three nodes automatically.