cluster

command
v1.61.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cluster

Two ygo servers that share their documents through a backplane, as instances behind a load balancer do.

go run ./examples/cluster
alice on server one, bob on server two
both see: [alice: draft the plan bob: review it]
bob sees alice's presence: {"name":"alice"}
alice left: her presence is gone on server two

Alice's client connects to server one, Bob's to server two. Their edits and presence cross between the servers only through the backplane, the in-process hub here (backplane.NewMemory).

Things to copy right:

  • One connection per server. Each server gets its own hub.Conn() (or its own Redis or NATS backplane value): a server never gets back what it published, so two servers sharing one connection would not hear each other.
  • A shared Store in production. These servers have none, so the example proves the backplane carries the updates. In production every instance needs the same persist.Store (a database all instances reach): a document loaded on an instance after others edited it comes from the Store, and the backplane only relays live updates.
  • Shut down in order: clients, then each server's HTTP listener, then the server (Close also closes its backplane connection), each with its own bounded context.

Across processes

The same with Redis, in your own module (go get github.com/Deln0r/ygo/server/backplane/redis):

rdb := redis.NewClient(&redis.Options{Addr: "redis.internal:6379"})
bp, err := redisbp.NewStreams(rdb) // or redisbp.New(rdb) for Pub/Sub
srv := server.New(server.Options{Store: sharedStore, Backplane: bp})

or with NATS (github.com/Deln0r/ygo/server/backplane/nats). Each instance builds its own backplane value against the same Redis or NATS. See server/backplane/redis and server/backplane/nats for what each guarantees.

Documentation

Overview

Command cluster runs two ygo servers that share their documents through a backplane, as instances behind a load balancer do.

go run ./examples/cluster

A client on each server edits one document and sees the other's edits and presence, which cross from one server to the other only through the backplane. Here the backplane is the in-process hub; across processes, the Redis (server/backplane/redis) and NATS (server/backplane/nats) adapters take its place (see README.md).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL