Ten Reactive Design Patterns
Patterns are not any kind of universal truth, but knowing them gives you vocabulary to express intent. Today, let's talk about Reactivity.
Reactive systems work like a deterministic state graph with two clear boundaries: Event Ingress (#1) as the entry point from the imperative world, and Side Effects (#10) as the exit point back to the outside world.
1. Event Ingress
Ingest discrete external events and continuous streams into the reactive state graph, translating imperative impulses into state updates with automatic subscription cleanup.
-
Use Case: Capturing a button click, listening to window resize events, or receiving real-time messages from a WebSocket connection.
-
Sample implementations: DOM Event Handlers (
onClick,@input),addEventListenerwith cleanup, AngulartoSignal(), Solidfrom(), VueUseuseEventListener/useWebSocket, JavaFXEventHandler/ ReactFXEventStreams.
2. Atomic State
Create and update simple, single-value reactive units that notify dependents whenever their value changes.
-
Use Case: Tracking a counter, a toggle flag (
isOpen), an active tab ID, or the current text inside a search input. -
Sample implementations: Angular
signal(), SolidcreateSignal(), Vueref(), JavaFXSimpleObjectProperty/SimpleIntegerProperty.
3. Shallow / Deep State
Manage complex objects, lists, and nested structures by choosing between top-level reference tracking (shallow) or fine-grained nested reactivity (deep).
-
Use Case: Handling a multi-step form object, a shopping cart array, or a large dataset where only top-level replacement should trigger updates.
-
Sample implementations: Vue
reactive()/shallowRef(), SolidcreateStore(), Angularsignal()with immutable updates / NgRxsignalState(), JavaFXFXCollections.observableArrayList()(withextractorfor deep tracking).
4. Derived State
Compute cached values from existing state that evaluate lazily or eagerly and only recalculate when their specific dependencies change.
-
Use Case: Calculating a shopping cart total with taxes, filtering a list based on a search query, or checking if a form is valid.
-
Sample implementations: Angular
computed(), Vuecomputed(), SolidcreateMemo(), JavaFXBindings.createObjectBinding()/ObservableValue.map().
5. Writable Derived State
Create state that automatically resets or recalculates when a source changes, while still allowing manual user overrides in between.
-
Use Case: Selecting the first shipping option by default whenever the user changes their country, yet letting them manually pick another option.
-
Sample implementations: Angular
linkedSignal(), Vuecomputed({ get, set }), SolidcreateWritableMemo()(@solid-primitives/memo), JavaFXbindBidirectional()/ChangeListenerupdating a writableProperty.
6. Remote State
Represent asynchronous remote data as reactive state, declaratively managing loading status, errors, and automatic cancellation of stale requests.
-
Use Case: Fetching user profile details or search results from a REST API whenever a
userIdorquerysignal changes. -
Sample implementations: Angular
resource()/httpResource(), SolidcreateResource(), Vuewatch()withonWatcherCleanup()/ TanStack Query, JavaFXjavafx.concurrent.Task/Service.
7. Untracked Read
Read the current value of a reactive node inside an effect or derivation without subscribing to it, preventing unwanted re-executions and loops.
-
Use Case: Logging a user action along with the current theme or user ID inside an effect without re-running the log when the theme changes.
-
Sample implementations: Angular
untracked(), Soliduntrack(), Vue explicitwatch(source, cb)(ignoring unmentioned refs), JavaFX explicitBindings(omitting dependencies from the dependency varargs).
8. State Throttling
Delay or rate-limit reactions to rapid state changes over time so downstream computations and network requests are not overwhelmed.
-
Use Case: Waiting 300ms after a user stops typing before triggering an autocomplete API search, or limiting scroll position updates.
-
Sample implementations: Angular
toObservable()+debounceTime()+toSignal(), VuecustomRef()/refDebounced()(VueUse), Soliddebounce()(@solid-primitives/scheduled), JavaFXPauseTransition/ ReactFXsuccessionEnds().
9. State History
Access previous state values for delta comparisons or maintain undo/redo stacks across state transitions over time.
-
Use Case: Highlighting whether a stock price went up or down compared to its previous tick, or building undo/redo in a text or canvas editor.
-
Sample implementations: Vue
watch(src, (curr, prev))/useRefHistory()(VueUse), SolidcreateEffect((prev) => ...)/createHistory(), AngularlinkedSignal(previousparam) / RxJSpairwise(), JavaFXChangeListener(obs, oldVal, newVal).
10. Side Effects
Synchronize internal reactive state back to the outside world using either automatic dependency tracking or explicit source subscriptions.
-
Use Case: Persisting user preferences to
localStorage, drawing onto an HTML<canvas>, or updatingdocument.titlewhen state changes. -
Sample implementations: Angular
effect(), VuewatchEffect()(implicit) /watch()(explicit), SolidcreateEffect()(implicit) /on()(explicit), JavaFXInvalidationListener(lazy) /ChangeListener(eager).
Conclusion
This list is not exhaustive, as reactive programming spans many domain-specific and low-level engine concerns. However, these ten patterns cover the most relevant and practical scenarios required to design, scale, and maintain modern reactive applications.