Skip to main content
Version: Next

Flow Structure

A flow in Lunar.dev is a structured collection of processors working together to manage API traffic. Flows define how requests and responses are processed, with each flow represented in the flow.yaml file. This modular setup allows you to precisely control traffic by processing API requests and responses in real-time.

Flows are divided into two main streams:

  • Flow Request Stream: Manages incoming API requests using defined processors.
  • Flow Response Stream: Handles outgoing API responses by applying specific processors.

From/To Definitions

The core of a flow's structure relies on the from and to configurations. Each processor in a flow reads data from an input stream (defined in the from section) and sends its output to an output stream or another processor (defined in the to section). This modular connectivity allows processors to work together in a flexible graph, giving you control over how traffic moves through the system.

For example:

  • A processor may read from the global stream at the start of the request and apply rate limiting.
  • Depending on the outcome (blocked or allowed), the request is either forwarded to the next processor or handled with a custom response.
/etc/lunar-proxy/flows/flow.yaml
# Flow Structure Example: Connecting processors via streams
flow:
request:
- from:
stream:
name: globalStream # Input stream for the flow
at: start
to:
processor:
name: Limiter # Apply rate limiting to the request

- from:
processor:
name: Limiter
condition: above_limit # Handle requests exceeding the rate limit
to:
processor:
name: GenerateResponse # Respond with a custom message

- from:
processor:
name: Limiter
condition: below_limit # Forward allowed requests
to:
stream:
name: globalStream
at: end

Additional Features

  • Modular Execution: Flows can call other flows, allowing you to scale and reuse configurations easily.
  • Validation Checks: Built-in checks ensure flows are configured correctly, preventing misconfigurations or incomplete flows.
  • Custom Logic: Design custom traffic management strategies by combining multiple processors and creating modular workflows.

This flexible flow structure allows organizations to create efficient, scalable traffic control solutions that fit both legacy and modern environments. With flows, you can design robust policies for managing API consumption, enforcing rate limits, or customizing responses based on specific conditions.

By leveraging Lunar's flow structure, you ensure that traffic is processed smoothly while maintaining complete control over API interactions.

CTRL + M