Example: Hybrid Service
A hybrid node is a cluster node, a satellite and a client in one process. Every node routes and hosts, so a small deployment needs no separate routing tier. This is how most services built on MLambda.Actor run: MLambda.Data, MLambda.OAuth and MLambda.EBank are hybrid nodes.
Starting a hybrid node
startHost system (guardedBy guard (hostConfig Hybrid self seeds hostings))
On NODE_PORT it is a cluster node; on the next port, a satellite hosting hostings for that node; on the one after,
an asteroid. Its client asks through the cluster, so it reaches its own actors and every other node’s the same way.
From the environment, a service needs only its hostings:
import Surround.Config
hostedFromEnv :: ActorSystem -> [Hosting] -> Either Fault ActorClient
hostedFromEnv system hostings = case startHost system (hostConfigFromEnv hostings) of
Right host -> Right (hostClient host)
Left fault -> Left fault
with ACTOR_TOPOLOGY=hybrid, NODE_ID, NODE_HOST, NODE_PORT and SEEDS set.
In compose
compose.hybrid.yml runs one hybrid node and a client:
services:
hybrid:
<<: *demo
environment:
DEMO_ROLE: hybrid
NODE_ID: hybrid
NODE_HOST: hybrid
NODE_PORT: "5000"
client:
<<: *demo
depends_on: [hybrid]
environment:
DEMO_ROLE: client
NODE_ID: client
NODE_HOST: client
NODE_PORT: "6000"
SEEDS: "hybrid:5000"
STARTUP_DELAY: "2000"
cd MLambda.Actor.Demo
docker compose -f compose.hybrid.yml up --build --abort-on-container-exit --exit-code-from client
A service of hybrid nodes
MLambda.Data’s cluster topology is three hybrid nodes seeding each other; its fortress topology is the same with
FORTRESS_IDENTITY (each node’s identity, issued by the cluster’s CA). Each node serves the HTTP API and answers from the cluster, so a request can go to any of them.