Technical Insight Explanation

Knative Eventing: Building Event-Driven Applications on Kubernetes

Understand CloudEvents, Sources, Brokers, Triggers and delivery semantics in Knative Eventing.

Knative Eventing: Building Event-Driven Applications on Kubernetes
On this page

An HTTP request normally knows where it is going. An event should not need to know who is interested in it.

That distinction changes the architecture. A producer announces that something happened; consumers decide what to do with that information. In Understanding Knative: How Scale to Zero actually works , we explored request-driven activation. Here we examine the infrastructure that connects asynchronous producers and consumers.

The event contract

CloudEvents standardizes event metadata, not business semantics or transport durability. An event has required attributes including id, source, specversion and type. The combination of source and id identifies a distinct event. Consumers must still agree on the payload schema, its evolution and the meaning of the event type.

In HTTP binary mode, attributes are conveyed in headers and the payload remains the body. Structured mode encodes the event as a single envelope. Neither mode guarantees delivery.

Sources, Brokers and Triggers

A Source adapts an event producer to a destination. A Broker provides an event ingress and distribution abstraction. A Trigger selects events from a Broker and identifies a subscriber. These are Kubernetes resources reconciled by controllers, not a universal message queue implementation.

Event distribution

A Broker may use different implementations, including Kafka-backed implementations. Persistence, ordering, throughput and failure behavior depend on that implementation and its configuration. Installing Eventing alone does not establish a durable event log.

A Source can also deliver directly to an addressable sink without a Broker. Use a Broker when routing and independent subscriptions justify the additional infrastructure.

A minimal routing experiment

Assume Eventing and a supported default Broker implementation are installed, along with Serving if using a Knative Service as the subscriber. The manifest below defines a Broker, a Trigger and a subscriber Service:

apiVersion: eventing.knative.dev/v1
kind: Broker
metadata:
  name: orders
---
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: order-created
spec:
  broker: orders
  filter:
    attributes:
      type: com.example.order.created
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: event-display
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: event-display
spec:
  template:
    spec:
      containers:
        - image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display

Save the manifest as eventing.yaml (or apply it directly via kubectl apply -n events-demo -f -) in an isolated namespace and wait for the resources to become ready:

kubectl create namespace events-demo
kubectl apply -n events-demo -f eventing.yaml
kubectl -n events-demo get broker,trigger,ksvc
kubectl -n events-demo wait --for=condition=Ready broker/orders --timeout=180s
kubectl -n events-demo wait --for=condition=Ready trigger/order-created --timeout=180s
kubectl -n events-demo wait --for=condition=Ready ksvc/event-display --timeout=180s

Retrieve the Broker address and send a CloudEvent from inside the cluster:

BROKER=$(kubectl -n events-demo get broker orders -o jsonpath='{.status.address.url}')
kubectl -n events-demo run sender --rm -i --restart=Never --image=curlimages/curl -- \
  -sS --fail-with-body -X POST "$BROKER" \
  -H 'ce-specversion: 1.0' -H 'ce-id: order-001' \
  -H 'ce-source: /demo/orders' -H 'ce-type: com.example.order.created' \
  -H 'Content-Type: application/json' -d '{"orderId":"001"}'

Inspect subscriber logs with kubectl -n events-demo logs -l serving.knative.dev/service=event-display -c user-container --tail=50. The example image must be available to the cluster; the manifests use an illustrative upstream sample tag. A successful response from the Broker confirms acceptance according to its implementation, not successful processing by every subscriber.

Change the event type and send another event with a distinct id. The Trigger should not match it. This is a routing experiment, not a durability test.

Delivery failures are part of the interface

A consumer may commit a database transaction and then lose its HTTP response. The delivery system sees a failure and may retry. The consumer sees the same event twice. Both are behaving reasonably.

Delivery and retries

Configure retries, backoff and a dead-letter sink where supported by the selected Broker implementation. A dead-letter sink is a destination for failed delivery, not automatically a durable archive. Monitor it and define replay procedures.

Design consumers to be idempotent. A common pattern is a unique database constraint on (event_source, event_id) with the deduplication record and business mutation committed in the same transaction. External side effects require their own idempotency strategy or an outbox. Acknowledging before committing risks losing work; acknowledging afterward can produce duplicates. Exactly-once business effects cannot be inferred from a transport acknowledgement.

Ordering and backpressure

Multiple consumers, retries and concurrent delivery can reorder events. If order matters, define a partition key and verify the guarantees of the selected implementation. Include entity versions in events where consumers need to detect stale updates. Do not assume a Trigger provides global ordering.

Backpressure is equally important. If consumers process 100 events per second and producers generate 150, backlog grows by roughly 50 events per second while those rates persist. Scaling consumers may help, but a database or external API may be the real bottleneck. A durable Broker can absorb a bounded backlog; it cannot eliminate a sustained capacity deficit.

Serving and Eventing together

A Trigger can deliver HTTP events to a Knative Service. If the service has scaled to zero, its activation path can add latency to delivery. Retry timeouts, startup time and downstream capacity must therefore be considered together. Eventing does not itself turn every subscriber into a scale-to-zero workload. A conventional Deployment can also be a subscriber.

Operational boundaries

Treat Broker ingress as a security boundary. Restrict network access and apply authentication and authorization appropriate to the chosen implementation. CloudEvents attributes are metadata, not proof of identity. Validate payloads, limit event size, avoid secrets in events and establish retention policies.

Monitor accepted events, delivery latency, retry rates, backlog where available, dead-letter volume and consumer errors. Correlate by source and id, while avoiding unbounded metric label cardinality.

The next article compares Knative, KEDA and HPA . They all respond to demand, but they observe different signals and make different lifecycle decisions.

Upstream references

Related Articles

Stay ahead

Get the latest insights.

Insights on cloud, AI and open source — delivered to your inbox.

Email subscriptions are coming soon.