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

Taught in

References

Certification courses