Choose the right Clojure reference type for changing identity: atoms for independent synchronous state, refs for coordinated transactions, agents for asynchronous updates, and Vars for namespace or dynamic context.
Clojure separates immutable values from managed references. A value can be shared freely because it does not change. A reference is the explicit place where a newer value can replace an older value.
For Java engineers, the important shift is that state is not hidden behind many setter methods. You choose a reference type based on coordination:
| Tool | Best fit | Java comparison |
|---|---|---|
| Atom | One independent identity that changes synchronously. | AtomicReference with functional updates. |
| Ref | Several identities that must change together. | Database transaction more than synchronized. |
| Agent | One independent identity updated asynchronously. | Serialized worker queue with state. |
| Var | Namespace definition or dynamic per-thread context. | Static binding plus scoped thread context. |
This section is a decision guide. Start with values and pure transition functions, then add the smallest reference type that matches the coordination problem.