Docs menu
Build a scenario
Scenario file Generators vars and const Time and pace Defaults Relationships Schedules Instances Lifecycle Collections Connections Delivery behaviorBuild a scenario
Relationships
Random customer ids are not useful if they point to people who were never generated. ref() lets one generator select a real event from another generator.
The result we want
The id and name on an order must come from the same earlier customer:
{"customerId":"CUST-00","name":"Paul Considine"}
{"orderId":"ORD-00","customerId":"CUST-00","customerName":"Paul Considine","item":"Wireless headphones"}
Select a generated customer
Each order selects a customer event that already exists. You do not need a schedule for this: ref(customers) tells Synthtraffic that orders depends on customers, so it creates source history before the first order is evaluated.
Orders that belong to existing customers
defaults:
seed: 42
generators:
- name: customers
config:
maxEvents: 2
value:
customerId: =seq(format=CUST-%02d)
name: =faker(person.fullName)
- name: orders
config:
maxEvents: 2
vars:
customer: =ref(customers)
value:
orderId: =seq(format=ORD-%02d)
customerId: $customer.customerId
customerName: $customer.name
item: Wireless headphones
Press Try it. A customer appears before the first order. The streams can then continue together, and every order uses a customerId and customerName from a customer generated earlier.
How the relationship is built
ref(customers)tells Synthtraffic that customer events must exist first.- Synthtraffic generates and retains a customer before evaluating the first order.
ref(customers)selects one complete retained customer event.vars.customerkeeps that selected record available while the order is built.$customer.customerIdand$customer.namecopy matching fields into the order.
Keeping the complete customer in vars matters: the id and name always come from the same person.
The scenario uses seed: 42, so the generated names and customer selections repeat on another run.
ref versus previous
- Use
ref(customers)for an event from another generator. - Use
previous()for the earlier event from the same generator.
ref() cannot point at its own generator. ref and previous covers field paths, selection options, and same-stream examples.
You only need a schedule when you want stronger ordering—for example, finishing all customers before the first order. The automatic ordering from ref() is enough when each order only needs an existing customer.