Queues
Queues enable sophisticated multi-step data extraction workflows where one endpoint collects data (such as records or identifiers )that is used by subsequent endpoints. This is essential for APIs that require separate calls to fetch related data.
Queue Architecture
Queue Usage
Queues are auto-detected from your endpoint definitions — Sling discovers them by scanning processor output: and iterate.over: expressions. You do not need to declare them.
⚠️ Deprecated: The top-level
queues:list is no longer required and is ignored at runtime. Old specs that still include it continue to load, but Sling emits a one-time deprecation warning. Remove the field when you next touch the spec.
At load time, Sling enforces that every consumed queue has at least one producer, so typos surface immediately as a queue(s) with no producer error rather than at runtime.
1. Sending Data to Queues
Use processors to send data from one endpoint to a queue:
2. Consuming Data from Queues
Use the iterate section to process each item from a queue:
Queue Consumption: deferred vs immediate
deferred vs immediateThe iterate.consume option controls when a consumer reads its queue:
deferred (default)
The consumer waits for the producer to fully finish, then reads the queue from the start.
immediate
The consumer tails the queue live — it starts processing as soon as the producer appends records, running concurrently with the producer.
When to use each
deferred(default) — Use when the consumer needs the complete set of queue items before it can do its job, such as deduplication or aggregation across all records. Also the safest choice for ordinary fan-out where you don't need pipelining.immediate— Use when you want pipelined throughput (the consumer works while the producer is still fetching) and fail-fast behavior.
Fail-fast with immediate
immediateWhen a consumer uses consume: immediate, Sling runs the producer and its live consumers concurrently (it forces threaded execution, equivalent to setting SLING_THREADS). The producer plus all the consumers that tail its queue form a fail-fast group:
If a consumer fails, its producer (and the other consumers in the same group) are terminated — Sling stops pulling data that nothing will use.
If a producer fails, the consumers tailing its queue are terminated — they would otherwise block forever waiting for a queue that will never complete.
Unrelated streams and other queue groups are not affected — they continue and can finish successfully.
This avoids wasted work: with the default deferred consumption, a producer always runs to completion before the consumer even starts, so a later consumer failure means the entire producer fetch was wasted. immediate surfaces failures early while the producer is still running.
💡 Tip:
immediateonly changes behavior for queue iteration. It has no effect on non-queueiterate.overexpressions (arrays,range(), etc.).
Queue-Only Endpoints
Some producer endpoints exist only to fan IDs into a queue for a downstream consumer — they don't produce records anyone wants to read. Mark them with queue_only: true and Sling will:
run the endpoint and drain its records into the queue(s) it populates via processors,
skip emitting a record stream (no target write, no row count),
hide the endpoint from
*wildcard discovery and fromsling conns discover,still schedule the endpoint to run before any consumer that iterates over its queue (dependency order is auto-detected).
The endpoint is still selectable by explicit name when you need to debug it.
Example: Search → Detail
In a replication that targets *, Sling will run search first (filling queue.imdb_ids) and then details (writing one row per movie). search does not appear in conns discover output or in the wildcard endpoint list — list it explicitly by name to inspect it.
💡 Tip:
queue_onlyreplaces the older pattern of writing throwaway records from a producer endpoint just to satisfy the "every endpoint must produce a stream" assumption. Combined with auto-detected queues, your producer/consumer wiring stays declared in exactly one place: the endpoints themselves.
Queue Functions
Queues can be used with built-in functions for advanced processing:
Chunking Queue Data
Process queue items in batches for more efficient API calls:
Real-World Example: Stripe API
This example from the Stripe API demonstrates a complete queue-based workflow:
Queue Properties and Behavior
Queue Characteristics
Temporary Storage
Queues are backed by temporary files
Automatically cleaned up after run
FIFO Order
Items are processed in first-in, first-out order
IDs processed in the order they were added
JSON Encoding
All data is JSON-encoded for safe storage
Handles strings, numbers, objects, arrays
Single Run Scope
Queues exist only within a single Sling execution
Cannot persist between separate runs
Queue Lifecycle
Direct Queue-to-Records Pattern
You can pipe queue data directly to records without making HTTP requests using the special syntax iterate.into: "response.records".
Basic Syntax
When to Use
Deduplicate queue items before further processing
Enrich queue data with state variables
Transform queue structure
Export queue contents as a separate dataset
Example: Deduplication Workflow
Data Type Handling
Scalar values (strings/numbers) are wrapped: "user123" → {"value": "user123"}
Object values are used as-is: {"id": 1, "name": "Alice"} → same structure
Limitations
No HTTP response data (
response.status,response.headersunavailable)Cannot use pagination or response rules
Don't define a
requestblock (it will be ignored)
💡 Tip: This pattern is much faster than unnecessary HTTP requests for queue transformation steps.
Advanced Queue Patterns
Pattern 1: Multi-Level Hierarchies
Process nested data structures with multiple queue levels:
Pattern 2: Conditional Queue Population
Only queue certain items based on conditions:
Pattern 3: Queue Transformation
Transform data before queuing:
Queue Best Practices
Performance Optimization
Error Handling with Queues
💡 Tip: Use descriptive queue names that clearly indicate their purpose (e.g.,
customer_ids,pending_order_ids,failed_payment_ids).
⚠️ Warning: Queues consume disk space proportional to the number of items. For very large datasets (millions of items), monitor available disk space.
📝 Note: Queue items are automatically JSON-encoded, so complex objects, arrays, and special characters are handled safely.
Last updated
Was this helpful?