In an event-driven architecture each component only acts when an event is sent through the system.
Imagine a hypothetical car with a brake pedal and a brake light.
- The brake light turns on when it receives a brake_on event, and off when it receives a brake_off event.
- The brake pedal sends a brake_on event when it is pressed down, and a brake_off event when it is released.
This is all well and good, until you have the situation where the car is turned on with the brake pedal already pressed down. Since the brake light never received a brake_on event, it will stay off - clearly an undesirable situation. Turning the brake light on by default only reverses the situation.
What could be done to resolve this 'initial state problem'?
EDIT: Thank you for all the responses. My question was not about an actual car. In cars they solved this problem by continuously sending the state - therefore there is no startup issue in that domain. In my software domain, that solution would use many unnecessary CPU cycles.
EDIT 2: In addition to @gbjbaanb's answer, I'm going for a system in which:
- the hypothetical brake pedal, after initialization, sends an event with its state, and
- the hypothetical brake light, after initialization, sends an event requesting a state event from the brake pedal.
With this solution, there are no dependencies between components, no race conditions, no message queues to go stale, and no 'master' components.