What Triggers Code Execution? A Complete Guide to Events & Actions
Code doesn't run on its own—it waits for a trigger. The trigger depends entirely on the application type, architecture, and language. Here’s a taxonomy of the most common execution triggers across software domains.
1. User Interactions (Frontend / GUI / Mobile)
- Click/Tap: Buttons, links, icons, list items.
- Form Events: Submit, input change, blur, focus, validation.
- Hover/Touch: Tooltips, dropdowns, drag-start.
- Gesture: Swipe, pinch, long-press.
- Keyboard: Keydown/up, shortcuts, accessibility triggers.
2. System & OS Events (Backend / Embedded / OS)
- Scheduled/Timer: Cron jobs, `setTimeout`/`setInterval`, Windows Task Scheduler, systemd timers.
- File System: inotify (Linux), FSEvents (macOS), FileSystemWatcher (.NET) — create, delete, modify, rename.
- Network: Incoming HTTP/TCP/UDP request, WebSocket message, DNS change, connection open/close.
- Hardware/Interrupts: GPIO pin change, sensor threshold, USB device insert, CPU interrupt (IRQ).
- Process Signals: SIGTERM, SIGINT, SIGHUP, SIGUSR1/2 (Unix/Linux).
3. API & Integration Triggers
- Incoming HTTP Request: REST, GraphQL, gRPC, webhook POST.
- Webhooks: Async callbacks from Stripe, GitHub, Slack, Twilio, Shopify.
- Message Queue / Event Bus: Kafka, RabbitMQ, SQS, Pub/Sub, Redis Streams — consumer pulls message.
- Database Changes: CDC (Change Data Capture), triggers, CDC tools (Debezium).
4. Language/Framework Constructs
- Event Listeners/Handlers: `addEventListener`, `on()`, `.on()`, delegates, observers.
- Exceptions/Errors: `try/catch`, global error handlers, unhandled promise rejection.
- Lifecycle Hooks: `ngOnInit`, `useEffect`, `componentDidMount`, `onCreate`, `ApplicationRunner`.
- Reactive Streams: RxJS, Reactor, Flow — subscription triggers emission.
5. Application-Specific Loops
- Game Loop: Fixed timestep `update()` / `render()` (60/120 FPS).
- Real-Time Stream Processing: Flink, Spark Streaming, Kafka Streams — event-time/windows.
- Serverless / FaaS: AWS Lambda, Cloud Functions, Azure Functions — triggered by HTTP, queue, schedule, storage event.
- CI/CD Pipeline: Git push, PR open, tag, schedule, manual dispatch.
Key Takeaway
Identify the trigger by asking: "What is the entry point for this code path in this specific runtime?" The answer lives at the intersection of platform, framework, and architecture.