Every Clojure service starts the same way: a def holding a database connection, a def holding a queue channel, and a comment in the README saying “call (reset) after editing.” That works until the third namespace needs the same connection pool, the REPL reloads it twice, and production starts leaking connections at a rate that only shows up on Fridays.

The fix is a lifecycle library — and Clojure has exactly three serious contenders. Component (2,168 stars, last push 2025-10-25, com.stuartsierra/component 1.2.0, 20.6M Clojars downloads) makes dependencies an explicit graph of records. Integrant (1,371 stars, last push 2026-01-07, integrant 1.0.1, 4.8M downloads) makes the graph a plain data map you can read from EDN and reload key by key. Mount (1,255 stars, last push 2026-06-11, mount 0.1.24, 5.7M downloads) makes state a top-level defstate you can require from anywhere.

TL;DR

  • Choose Component if you want compile-time clarity, explicit dependency declarations, and a system map you can pass into functions during tests.
  • Choose Integrant if you want configuration as data, per-key reloading in the REPL, and the ability to strip a key out of the system without touching code.
  • Choose Mount if your app is small, you like defstate next to the code that uses it, and you accept global state as a deliberate trade.
  • Do not mix all three in one codebase. Pick one for application wiring and keep test fixtures plain.

Comparison table

DimensionComponentIntegrantMount
Stars / last push2,168 / 2025-10-251,371 / 2026-01-071,255 / 2026-06-11
Latest artifact1.2.01.0.10.1.24
Clojars downloads20.6M4.8M5.7M
LicenseMITMITEPL-1.0
Wiring styleRecords implementing LifecycleMultimethods on keyword keysGlobal defstate vars
Dependency declarationsystem-using / constructor argsig/ref, ig/refsetImplicit var references
Config sourceClojure codeClojure or EDNClojure code
Reload granularityWhole systemIndividual key via ig/suspend!Whole system or single state
Test ergonomicsExcellent — pass a mapExcellent — pass a mapWeak — global state
Cycle detectionYes, at system-map build timeYes, at init timeNone
Learning curveMediumMedium-highLow

Decision matrix

Your situationUseWhy
Multi-service backend with a strict start orderComponentDependency graph is validated before anything starts
Config lives in EDN and ops edits itIntegrantConfig is a literal data structure, #ig/ref is readable
Small CLI or single-purpose serviceMountTwo lines to start, no ceremony
Heavy REPL workflow, want to restart one keyIntegrantig/suspend! / ig/resume restarts a subtree only
You need to hand a partially mocked system to a testComponent or IntegrantBoth are plain maps
Team is new to ClojureMount first, then Integrantdefstate teaches the idea without abstractions

Component: the explicit graph

Component’s core idea is that a “component” is a record with start and stop methods, and that dependencies are constructor arguments. Here is the canonical shape, straight from the project’s README:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
(defrecord Database [host port connection]
  component/Lifecycle

  (start [component]
    (println ";; Starting database")
    (let [conn (connect-to-database host port)]
      (assoc component :connection conn)))

  (stop [component]
    (println ";; Stopping database")
    (.close connection)
    (assoc component :connection nil)))

You then assemble a system and declare who uses whom:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(require '[com.stuartsierra.component :as component])

(defn system [config]
  (component/system-map
    :db   (db/database (:db config))
    :cache (cache/redis (:cache config))
    :app  (component/using
            (app/handler (:app config))
            [:db :cache])))

(def sys (component/start (system config)))
;; later
(component/stop sys)

component/start walks the graph in dependency order, component/stop walks it in reverse. If a key is missing or a cycle exists, system-map fails loudly at construction time — the single most useful property in this comparison, because it turns a runtime NullPointerException into a startup error.

The discipline it demands: every start must return the updated component, and every consumer must receive dependencies through its constructor. Skip that and you are back to global state with extra steps.

Integrant: configuration as data

Integrant keeps the same lifecycle semantics but replaces records with multimethods keyed by keywords, and dependencies with ig/ref inside a config map:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(require '[integrant.core :as ig])

(def config
  {:adapter/jetty {:port 8080, :handler (ig/ref :handler/greet)}
   :handler/greet {:name "Alice"}})

(defmethod ig/init-key :handler/greet [_ {:keys [name]}]
  (fn [_] (resp/response (str "Hello " name))))

(defmethod ig/init-key :adapter/jetty [_ {:keys [handler] :as opts}]
  (jetty/run-jetty handler (-> opts (dissoc :handler) (assoc :join? false))))

Because the config is pure data, the same map can live in resources/config.edn:

1
2
3
;; config.edn
{:adapter/jetty {:port 8080, :handler #ig/ref :handler/greet}
 :handler/greet {:name "Alice"}}

and be loaded with (ig/read-string (slurp "resources/config.edn")). The operational payoff is real: change one key’s value, call ig/suspend! on that key, ig/init-key again, and you have restarted a single component without touching the Jetty listener or the connection pool. ig/halt! shuts down in reverse dependency order, and ig/prep validates that every ig/ref points at a key that exists before anything starts.

The cost is indirection: dependencies are strings in a map rather than function arguments, so your editor cannot jump from :handler/greet to its implementation as reliably as it can from a constructor parameter.

Mount: state without ceremony

Mount takes the opposite approach — state is a top-level var, started and stopped by a macro:

1
2
3
4
5
6
(ns app.db
  (:require [mount.core :refer [defstate]]))

(defstate conn
  :start (create-conn)
  :stop  (disconnect conn))

Any namespace can then (require '[app.db :refer [conn]]) and use it directly. (mount/start) starts every state in load order, (mount/stop) stops them in reverse, and (mount/start-with-states {#'app.db/conn ...}) lets you substitute implementations for tests.

That is genuinely pleasant for a 2,000-line service, and it is why Mount has 5.7M downloads. It is also why teams outgrow it: state is global, so two tests running in parallel share a connection, and dependency order is inferred from namespace load order rather than declared. When the order is wrong, you get an IllegalStateException at startup and no graph to inspect.

Migration notes: moving between the three

The migration that actually happens in practice is Mount → Integrant, and it is mostly mechanical. defstate blocks become ig/init-key methods; the :start body moves into the method body; :stop becomes the ig/halt-key! method. Explicit references between states become ig/ref entries in a config map that you write down for the first time — which is exactly when teams discover two namespaces that depended on each other and only worked because of load order.

Component → Integrant is rarer and usually driven by a configuration requirement: once config must be EDN that ops can edit without a rebuild, records stop being the right container. Keep the Lifecycle protocol implementations and call them from ig/init-key methods; the state transitions are identical, only the wiring changes.

Going the other direction — Integrant → Component — is usually a mistake unless you specifically need constructor injection and compile-time graph validation. The components are already written as functions of their config; wrapping them in records adds a layer without adding a guarantee.

Whichever you pick, keep the boundary clean: application wiring in one namespace, business logic taking plain arguments. That single rule makes any of these libraries replaceable, and it is the difference between a codebase that survives a framework change and one that does not.

For the surrounding stack, our Ring vs Compojure vs Reitit comparison covers the HTTP layer these systems usually start, Clojure testing frameworks explains how to wire fixtures around a system map, and the build tools guide covers deps.edn aliases for REPL-driven work.

Pitfalls

  1. Component start must return the component. Returning nil or a bare connection breaks the graph silently; the next consumer receives nil and fails three layers away.
  2. Integrant ref cycles surface late. ig/prep catches missing keys, not circular references. Draw the graph before you write the config.
  3. Mount’s load order is implicit. A namespace that is never required never starts its state. Keep state namespaces in one place and require them from the entry point.
  4. Halt order matters. Connection pools must stop after the handlers that use them. Both Component and Integrant give you reverse order for free — do not simulate it by hand.
  5. Do not start systems inside test fixtures that also use with-redefs. Started components capture the real var; redefine before start, not after.
  6. REPL reload does not restart components. (reset) reloads namespaces; it does not call stop and start unless your tooling is wired to do so. Use integrant.repl or an equivalent that hooks reload to ig/halt!/ig/init.

FAQ

Which is fastest at startup? All three are negligible compared to JVM boot and connection setup. Integrant does slightly more work building the dependency order from data; Component validates the graph once at system-map time.

Does Component work with ClojureScript? No. Component is JVM-only. Mount supports ClojureScript, and Integrant itself is portable, though most init-key methods are not.

Can I use Integrant with a config file that ops edits? That is its main advantage. Use #ig/ref in EDN, load with ig/read-string, and validate with ig/prep at boot so a missing key fails fast instead of at first request.

Is Mount still maintained in 2026? Yes — the repository was pushed on 2026-06-11 and the current artifact is mount 0.1.24. Development is slow but the library is small and stable.

How do I test a system built with Component or Integrant? Start a system with test doubles substituted for the real databases, pass the resulting map into your handlers, then stop it in a finally block. Because both produce plain maps, no framework-specific test helper is needed.

Do I need a lifecycle library for a small service? No. One namespace with a main that starts a pool and a server, plus a shutdown hook, is fine under roughly a thousand lines. Add a lifecycle library when the second service needs the first one’s resources.



💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到技术监管时间线,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测技术相关事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com