Knative: Operator’s Handbook

Branching with Parallel

Parallel provides a way to define a list of services that will be invoked in parallel.

Here’s an example of a Parallel backed by an in-memory Channel and two Services invoked in parallel:

apiVersion: messaging.knative.dev/v1alpha1
kind: Parallel
metadata:
  name: parallel
spec:
  channelTemplate:
    apiVersion: messaging.knative.dev/v1alpha1
    kind: InMemoryChannel
  branches:
  - subscriber:
      ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: service1
  - subscriber:
      ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: service2

It’s typical to guard each branch with a filter function:

apiVersion: messaging.knative.dev/v1alpha1
kind: Parallel
...
spec:
  ...
  branches:
  - filter:
      ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: even-filter
    subscriber:
      ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: even-transformer
  - filter:
      ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: odd-filter
    subscriber:
      ref:
        apiVersion: serving.knative.dev/v1
        kind: Service
        name: odd-transformer

[Full example]

Parallel can optionally end with a global reply. In this case, it will end with a reply to a Service:

apiVersion: messaging.knative.dev/v1alpha1
kind: Parallel
...
spec:
  ...
  branches:
  ...
  reply:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: event-display

[Full example]