Backends
A backend provides the communication infrastructure that network programs run on.
After endpoint projection transforms a global Choreo into per-location Network
programs, a backend interprets the network operations (send, receive, broadcast)
using a concrete transport mechanism.
The Backend trait
Section titled “The Backend trait”trait Backend[B, M[_]]: extension (backend: B) def runNetwork[A](at: Loc)(network: Network[M, A]): M[A] extension (backend: B) def locs: Set[Loc]Backend[B, M] is a type class parameterized by:
B— the backend implementation type (e.g.,LocalBackend[M]orTcpBackend[M])M[_]— the effect type (e.g.,IO)
It provides two operations:
runNetwork(at)(network)— Interprets aNetwork[M, A]program at the given location, translatingSend,Recv,Broadcast, andParoperations into concrete effects.locs— Returns the set of all locations managed by this backend.
The Channel type
Section titled “The Channel type”type Channel = (from: Loc, to: Loc)A Channel is a named tuple identifying a directed communication path from one
location to another. Backends use channels to route messages — for example, the
local backend maintains one queue per channel, and the TCP backend maintains one
socket connection per channel.
From Choreo to execution
Section titled “From Choreo to execution”The typical flow from choreography to execution is:
// 1. Define a global choreographyval choreo: Choreo[IO, A] = ...
// 2. Create a backendval backend <- Backend.local(List(loc1, loc2))
// 3. Project and run at each locationval task1 = choreo.project(backend, loc1)val task2 = choreo.project(backend, loc2)
// 4. Run all tasks concurrently(task1, task2).parTupledThe .project(backend, loc) extension method on Choreo performs two steps internally:
-
Endpoint projection (EPP) — Transforms the global
Choreointo aNetworkprogram specific toloc. Operations involving other locations become sends, receives, or no-ops as appropriate. -
Interpretation — Passes the resulting
Networkprogram tobackend.runNetwork(loc)(...), which maps each network operation to concrete effects inM.
Available backends
Section titled “Available backends”| Backend | Transport | Use case |
|---|---|---|
| LocalBackend | In-memory queues | Testing, demos, single-process execution |
| TcpBackend | TCP sockets | Distributed execution across processes or machines |