side effect
Anything a piece of code does besides returning a value, such as writing to a database, sending a message or changing a variable outside it.
In more detail
Side effects are necessary but make code harder to test and retry: returning a value twice is harmless, charging a card twice is not. Keep them in known places and make repeated ones idempotent.
Examples
A Lambda handler should name the one side effect it owns and make it safe on a retry.Idempotent consumers guard the side effects of duplicated messages.Java streams: callbacks inside a pipeline should avoid side effects, especially in parallel.In React side effects must not happen while rendering: put them in event handlers or in an Effect.In this course: Side effects are where tests need doubles, temporary directories or real dependencies, and where reviewers should look for leaked state and failure handling. Code with fewer side effects needs fewer doubles to test.Related terms
- idempotency — The property of an operation that gives the same result whether you run it once or many times, because a repeat run finds nothing left to do.
- retry — Sending a request again after it failed or timed out, in the hope that it succeeds the second time.
- pure function — A function whose result depends only on its arguments and which has no side effects, so the same inputs always give the same output.
- Stream API — The standard-library toolkit for describing a sequence of data-processing steps, such as filter, map and collect, over a source like a list.
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
- mock — A test double that stands in for a real dependency and checks that the code under test calls it in the expected way.
- useEffect — The React hook for running side work, such as adding listeners or changing document.body, after a component renders.
- event handler — A function that runs when something happens to an element, such as a click (onClick) or a key press (onKeyDown).
- exactly-once semantics — A guarantee that each message's effects happen exactly once, even when senders retry or consumers crash.
- test double — Any object that replaces a real dependency in a test: a stub returns canned data, a fake is a small working implementation, and a mock checks interactions.
- shared mutable state — Data that several tests or requests can both read and change, so one can affect another.
Taught in
- Serverless Compute (Lambda) — Cloud Infrastructure & Hyperscaler Architecture
- Asynchronous Event Processing: Outbox Pattern & Queues — Production Full-Stack Engineering
- The Streams API — Modern Java: Virtual Threads & High-Throughput Services
- Designing Testable Code — Modern Java: Virtual Threads & High-Throughput Services
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Platform And Virtual Threads, Runnable And Callable — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Concurrent Collections And Parallel Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Native Test Runner: node:test & node:assert/strict — Node.js Internals & Backend Services
- Component Purity: Pure Functions, Idempotence And Side Effects — React 19 & Modern Component Architecture
- Complex State with useReducer: State Machines And Action Types — React 19 & Modern Component Architecture
- Virtual DOM vs Real DOM: The Reconciliation Cost Model — React 19 & Modern Component Architecture
- Custom Hook Composition: Encapsulating Reactive Logic — React 19 & Modern Component Architecture
- Idempotency, And Exactly Once As A Fiction — Scalable System Design & Distributed Architecture
- What To Look For In A Review — Automated Testing, TDD & Quality Engineering
References
- Creating event-driven architectures with Lambda
- MDN Glossary: Idempotent
- Java SE 21 API: java.util.stream package
- React docs: Keeping components pure (side effects)
- React: Where you can cause side effects
- React: Synchronizing with Effects
- Amazon Builders' Library: Making retries safe with idempotent APIs
- Python docs: functional programming HOWTO