Local runs and the cluster
Why a run on the local WorkManager behaves as the same workers do on the cluster: the per-event rules are the same code.
Local and on the cluster
Locally, everything happens in one process. A feedback loop, such as a strategy whose orders come back to it as positions, is a set of workers wired by topics, exactly as it would be deployed.
flowchart LR
NB["Notebook or test"] -->|"PublishAsync(topic, IObservable)"| BUS
subgraph LWM["LocalWorkManager (one process)"]
BUS["Local bus<br/>one subject per topic<br/>one global FIFO"]
RULES["WorkerEventRules<br/>prepare, process, finish, route"]
subgraph W["Workers, in deploy order"]
S["Strategy"]
E["SimulatedExecutor"]
P["FillPositions"]
end
BUS -->|"codec bytes"| RULES
RULES <--> W
RULES -->|"outputs by publishtopic or ce-type"| BUS
RULES -->|"worker throws"| DLQ["dlq.#lt;topic#gt;"]
end
S -. "order submitted" .-> E
E -. "order filled" .-> P
P -. "position" .-> S
BUS -->|"Observe(topic)"| OBS["Observers: tables, charts, asserts"]
DLQ -->|"ObserveDeadLetters(topic)"| OBS
On the cluster, the same worker runs in a WorkManager Runtime actor. The
per-event rules are the same code: WorkerEventRules lives in
Virtufin.Worker.Host, which both the Runtime and Virtufin.Behavior.DevKit
use.
flowchart LR
NB["Notebook"] -->|"gateway CreateWorker<br/>text/x-csharp or nupkg"| WM["WorkManager"]
WM --> ACT
subgraph RT["WorkManager Runtime"]
POOL["Redis-stream<br/>subscription pool"]
ACT["Runtime actor<br/>engine: C# source bridge, DLL or Python"]
RULES["WorkerEventRules<br/>prepare, process, finish, route"]
OUT["Outbox"]
POOL -->|"codec bytes"| ACT
ACT <--> RULES
RULES --> OUT
end
TOPICS["Pubsub topics"] --> POOL
OUT -->|"outputs by publishtopic or ce-type"| TOPICS
RULES -->|"worker throws"| DLQ["dlq.#lt;topic#gt;"]
One event, side by side
Each event a worker receives goes through the same steps locally and in the Runtime.
sequenceDiagram
autonumber
participant Pub as Publisher
participant Bus as Bus (local) or pubsub (cluster)
participant Rules as WorkerEventRules
participant W as Worker
participant Sub as Subscribers
Note over Bus,Rules: Same code locally and in the Runtime
Pub->>Bus: publish(topic, event)
Bus->>Rules: event as CloudEvents protobuf bytes
Rules->>Rules: PrepareInput: datacontenttype default,<br/>config fills missing attributes, secrets win
Rules->>W: ProcessAsync(input, context)<br/>context.Api: gateway (cluster) or LocalVirtufinApi (local)
alt worker returns outputs
W-->>Rules: outputs, in order
Rules->>Rules: FinishOutputs: id and source defaults,<br/>secret attributes stripped
Rules->>Rules: Route: publishtopic (stripped), else ce-type
Rules->>Sub: each output to its topic
Note right of Rules: an output with neither is logged and skipped
else worker throws
W--xRules: exception
Rules->>Sub: DeadLetter: the original event with dlq* attributes,<br/>once, to dlq.#lt;topic#gt;
Note right of Rules: processing continues with the next event
end