Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clojure project in the field

Clojure project in the field

Jérémie Grodziski

July 02, 2019

More Decks by Jérémie Grodziski

Other Decks in Programming


  1. Contexte Electre produit un service de recherche dans une base

    d’œuvres bibliographique (1,3M) mais également musicale, cinématographique et jeux vidéos. Ce service est utilisé par les bibliothèques, les libraires et e- commerçant avec environ 2M de notices et 4M de requêtes par jour.
  2. 4 Hexagonal Architecture SPA ClojureScript Re-frame PostgreSQL Google Cloud Solr

    Kafka Keycloak TDD Vault Architecture Decision Records Clojure Yada / Mount / HugSQL / Clojure.spec BDD / Scenari Command / Query / Event REST API BigQuery Tools.deps Struct. Logging Kub. / Docker EFK Prometheus Gitlab CI Shadow-cljs Cloud Storage (~S3) DDD Monorepo
  3. 5 « When you start modeling events, it forces you

    to think about the behavior of the system. As opposed to thinking about the structure of the system » Greg Young
  4. EVENT An Event represents a fact about the domain from

    the past Events are raised on every state transition that acknowledged the new fact as data in our system Event can reference the command or query identifier that trigger it Events can be ignored, but can’t be retracted or deleted, only a new event can invalidate a previous one Events are named with a past participle There are internal and external event: § Internal Events: the ones we raised and control in our Bounded Context § External Events: the ones from other upstream BC we subscribed to « Something happened that domain experts care about » E.Evans
  5. COMMAND A command represents an intention The result of a

    command can be either success or failure, the result is an event In case of success, state change(s) must have occured somewhere (otherwise nothing happened) Commands are named with a verb, in present tense of infinitive and a nominal group coming from the domain (entity of aggregate type) « A Command is a request made to do something »
  6. QUERY A query ask a system for data in a

    specific model Query never change the state of the system (they are idempotent) The query processing is often synchronous The query contains fields with some value to match for or an identifier Query can results in success or failure (not found) and long results can be paginated Queries are named with: “get” something (with identifier as arguments) or “find” something (with values to match as arguments) « A Query is a request asking to retrieve some data about the current state of a system »
  7. Submitted Paid … Command Event Order State § Customer Details

    § Order Lines (product + qty) § Shipping Info § Payment Receipt § … Submit Order Pay Order … Order Submitted Order Paid …

  9. Event Bus Event-Driven Architecture & Backend Software Architecture Command Query

    Internal Event Domain Logic Interface of the Backend System Each Command will trigger a state transition of the targeted Entity Event State Transition publish subscribe
  10. Event-Driven Architecture & Software Architecture Frontend Backend Command Query Internal

    Event Command Query Internal Event POST GET SSE or Websocket Hexagonal Architecture on the Backend Unidirectional Architecture on the Frontend REST API
  11. Why Clojure? Data processing and Frontend app with re-frame are

    the two main reasons Benefits § Simple, powerful and make people productive § Best language for Data Processing § Hosted (JVM / JS) easy interop with common infrastructure (Solr, Kafka, Keycloak, DBs, etc.) § Recruitment
  12. Why Clojure? Drawbacks § Recruitment § Decisions are to be

    made, nothing is served on a plate (like Spring, .Net) but allows great freedom and power
  13. Clojure Libraries: buy or build? For each library: Do I

    “buy” an existing one or build a closely fitted one? § Example with Solr § Example with Keycloak § Example with Kafka § Example with Scenari (BDD execution lib)
  14. Tools.Deps Love the simplicity and composability Not as rich and

    mature as Leiningen Shell scripts as “interface” for the developer. Minimal interface: build.sh / run.sh test.sh / release.sh “Metav” lib for version and release management
  15. Selling Clojure to managers Quick answer: it’s not Clojure A

    mix of trust (hence people), risk and cost. The only question is: can we deliver? For how much? In a polyglot world: platform is first, language is second. Infrastructure choice is costly, hexagonal architecture makes the investment in the domain logic perennial.
  16. TAKEAWAYS Clojure is fun and amazing! The interop is easy

    and the greatest benefit Immutability makes everything simpler and easier to reason about, always in flow The challenges are in the product and domain design, hence the organization and people, not the technology