Skip to main content

Why Tyk Streams?

Tyk Streams adds a declarative event layer on top of the Tyk Gateway, letting you expose or consume broker topics (Kafka, NATS, RabbitMQ…) through normal HTTP channels—REST, WebSocket, Server-Sent Events—without glue code. You can manage stream definitions in three interchangeable ways:
MethodWhen to use
Tyk Dashboard UIRapid prototyping and PoCs
OpenAPI + x-tyk-streaming“Everything-as-code”, safe for Git
Tyk Operator (Kubernetes CRD)GitOps & CI/CD pipelines

Requirements

  • Tyk Gateway ≥ 5.8 with Streams feature enabled
  • Apache Kafka reachable on localhost:9093
  • (Optional) Prometheus and Jaeger if you enable the commented observability blocks

Architecture

The demo shows a classic pattern: a user request becomes an event on a bus, a worker processes it asynchronously, and the result is delivered back to the same user—without leaking data across tenants.

Stream-per-responsibility pattern

StreamRoleInputOutput
inEdge entrypoint: accepts HTTP, enriches payload (user_id, job_id), publishes to jobs and echoes to callerHTTPKafka + sync response
WorkerBackground micro-service: listens to jobs, attaches result: "bar", publishes to completedKafkaKafka
outEdge exit point: listens to completed, drops messages not owned by caller, delivers via REST/WS/SSEKafkaHTTP

Processor mapping (built-in scripting)

Streams pipelines include processors. The mapping processor embeds Bloblang so you can transform or filter messages inline:
  • Enrichin adds user_id & job_id
  • AugmentWorker adds a static field { "result": "bar" }
  • Filterout calls deleted() for non-matching users
Dynamic placeholders ($tyk_context.…) can reference query params, headers, JWT claims, or any other context variable—usable anywhere in the Streams config.

Observability (optional)

Uncomment the metrics: and tracer: blocks to push per-stream Prometheus metrics and Jaeger traces. Tags like stream: Worker make end-to-end tracing trivial.

Full OpenAPI definition

Copy/paste into streams-demo.yaml, import via Dashboard UI, or apply with Tyk Operator:

Running the demo

  1. Start Kafka (e.g. docker-compose).
  2. Launch Tyk Gateway 5.8+ with the YAML above.
  3. Send an event
  4. Receive the result (only alice’s jobs)
  5. Switch transport – connect via websocket wscat -c http://127.0.0.1:8282/stream-demo/ws-in\?user\=alice
  6. (Optional) Enable metrics & tracing – uncomment blocks, restart Gateway, explore in Grafana & Jaeger.