Discovery is the system that automatically makes functions and triggers available across your entire backend application stack without manual configuration. When a worker connects and registers capabilities, they become immediately available to all other parts of the system.
Discovery eliminates the need for service registries, API gateways, or configuration files. Everything is registered dynamically over the WebSocket protocol.
External functions are special: they’re stored in external_function_ids and invoke HTTP endpoints instead of local handlers. The engine manages the HTTP lifecycle transparently.
Once a trigger type exists, any worker can register trigger instances:
// Any worker can now create HTTP triggersiii.registerTrigger({ type: 'http', // Must match registered type function_id: 'users.create', // Can be ANY function config: { api_path: 'users', http_method: 'POST' }});
If you register a trigger before its type exists, the trigger is stored but not activated. It activates automatically when the trigger type is registered later.
When a worker disconnects, the engine automatically cleans up all its registrations:
async fn cleanup_worker(&self, worker: &Worker) { // 1. Remove all regular functions let regular_functions = worker.get_regular_function_ids().await; for function_id in regular_functions.iter() { self.remove_function_from_engine(function_id); } // 2. Remove all external functions let external_functions = worker.get_external_function_ids().await; for function_id in external_functions.iter() { http_module.unregister_http_function(function_id).await?; } // 3. Halt all pending invocations let worker_invocations = worker.invocations.read().await; for invocation_id in worker_invocations.iter() { self.invocations.halt_invocation(invocation_id); } // 4. Unregister all triggers and trigger types self.trigger_registry.unregister_worker(&worker.id).await; // 5. Remove worker from registry self.worker_registry.unregister_worker(&worker.id);}
This automatic cleanup ensures that your system stays consistent even when workers crash or disconnect unexpectedly.