In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computer, computing machinery. It includes the study and experimentation of algorithmic processes, and the development of both computer hardware, hardware and softw ...
, an event is a detectable occurrence or change in the system's state, such as user input, hardware interrupts, system notifications, or changes in data or conditions, that the system is designed to monitor. Events trigger responses or actions and are fundamental to event-driven systems. These events can be handled synchronously, where the execution
thread is blocked until the event handler completes its processing, or asynchronously, where the event is processed independently, often through an
event loop
In computer science, the event loop (also known as message dispatcher, message loop, message pump, or run loop) is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by m ...
. Even when synchronous handling appears to block execution, the underlying mechanism in many systems is still asynchronous, managed by the event loop.
Events can be implemented through various mechanisms such as
callbacks
In computer programming, a callback is a function that is stored as data (a reference) and designed to be called by another function often ''back'' to the original abstraction layer.
A function that accepts a callback parameter may be design ...
, message objects, signals, or interrupts, and events themselves are distinct from the implementation mechanisms used. Event propagation models, such as
bubbling, capturing, and pub/sub, define how events are distributed and handled within a system. Other key aspects include event loops, event queueing and prioritization, event sourcing, and complex event processing patterns. These mechanisms contribute to the flexibility and scalability of
event-driven systems.
Events vs. Messages
In
distributed systems
Distributed computing is a field of computer science that studies distributed systems, defined as computer systems whose inter-communicating components are located on different computer network, networked computers.
The components of a distribu ...
, events represent a fact or state change (e.g., ''OrderPlaced'') and are typically broadcast asynchronously to multiple consumers, promoting loose coupling and scalability. While events generally don’t expect an immediate response, acknowledgment mechanisms are often implemented at the infrastructure level (e.g., Kafka commit offsets, SNS delivery statuses) rather than being an inherent part of the event pattern itself.
In contrast,
message
A message is a unit of communication that conveys information from a sender to a receiver. It can be transmitted through various forms, such as spoken or written words, signals, or electronic data, and can range from simple instructions to co ...
s serve a broader role, encompassing commands (e.g., ''ProcessPayment''), events (e.g., ''PaymentProcessed''), and documents (e.g., ''DataPayload''). Both events and messages can support various delivery guarantees, including at-least-once, at-most-once, and exactly-once, depending on the technology stack and implementation. However, exactly-once delivery is often achieved through idempotency mechanisms rather than true, infrastructure-level exactly-once semantics.
Delivery patterns for both events and messages include publish/subscribe (one-to-many) and point-to-point (one-to-one). While request/reply is technically possible, it is more commonly associated with messaging patterns rather than pure event-driven systems. Events excel at state propagation and decoupled notifications, while messages are better suited for command execution, workflow orchestration, and explicit coordination.
Modern architectures commonly combine both approaches, leveraging events for distributed state change notifications and messages for targeted command execution and structured workflows based on specific timing, ordering, and delivery requirements.
Event Evolution Strategies
In
distributed systems
Distributed computing is a field of computer science that studies distributed systems, defined as computer systems whose inter-communicating components are located on different computer network, networked computers.
The components of a distribu ...
, event evolution poses challenges, such as managing inconsistent event schemas across services and ensuring compatibility during gradual system updates. Event evolution strategies in event-driven architectures (EDA) can ensure that systems can handle changes to events without disruption. These strategies can include versioning events, such as semantic versioning or schema evolution, to maintain backward and forward compatibility. Adapters can translate events between old and new formats, ensuring consistent processing across components. These techniques can enable systems to evolve while remaining compatible and reliable in complex, distributed environments.
See also
*
Callback (computer programming)
In computer programming, a callback is a function that is stored as data (a reference) and designed to be called by another function often ''back'' to the original abstraction layer.
A function that accepts a callback parameter may be design ...
*
Database trigger
A database trigger is procedural code that is automatically executed in response to certain Event (computing), events on a particular Table (database), table or View (database), view in a database. The trigger is mostly used for maintaining the Dat ...
*
DOM events
*
Event-driven programming
In computer programming, event-driven programming is a programming paradigm in which the Control flow, flow of the program is determined by external Event (computing), events. User interface, UI events from computer mouse, mice, computer keyboard, ...
*
Exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
*
Interrupt handler
In computer systems programming, an interrupt handler, also known as an interrupt service routine (ISR), is a special block of code associated with a specific interrupt condition. Interrupt handlers are initiated by hardware interrupts, software ...
*
Interrupt
In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted ...
s
*
Observer pattern
In software design and software engineering, the observer pattern is a software design pattern in which an object, called the ''subject'' (also known as ''event source'' or ''event stream''), maintains a list of its dependents, called observers (a ...
(e.g., Event listener)
*
Reactor pattern
The reactor software design pattern is an event handling strategy that can respond to many potential service requests concurrently. The pattern's key component is an event loop, running in a ''single'' thread or process, which demultiplexes inc ...
vs.
Proactor pattern
Proactor is a software design pattern for event handling
In computing, an event is a detectable occurrence or change in the system's state, such as user input, hardware interrupts, system notifications, or changes in data or conditions, that the ...
*
Signal programming
SIGNAL is a programming language based on synchronized dataflow (flows + synchronization): a process is a set of equations on elementary flows describing both data and control.
The SIGNAL formal model provides the capability to describe systems ...
*
Virtual synchrony
Reliable multicast is any computer networking protocol that provides a '' reliable'' sequence of packets to multiple recipients simultaneously, making it suitable for applications such as multi-receiver file transfer.
Overview
Multicast is a ne ...
References
External links
* Article
Event Handlers and Callback Functions'
Distributed Events and Notifications*
Javadoc
Javadoc (also capitalized as JavaDoc or javadoc) is an API documentation generator for the Java programming language. Based on information in Java source code, Javadoc generates documentation formatted as HTML and other formats via extensions. ...
documentation
* Java package Javadoc API documentation
*
Java package
A Java package organizes Java classes into namespaces,
providing a unique namespace for each type it contains.
Classes in the same package can access each other's package-private and protected members.
In general, a package can contain the fo ...
Javadoc API documentation
Write an Event HandlerUnderstand Events (Logs and Metrics)
{{DEFAULTSORT:Event (Computing)
Computer programming
Subroutines