Slide 1

Slide 1 text

Clojure chez Electre Retour d’expérience

Slide 2

Slide 2 text

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.

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

MAKE COMMAND, QUERY AND EVENT FIRST CLASS CONCEPTS

Slide 7

Slide 7 text

EVENT FACTS, APPEND-ONLY Past Future Now COMMAND INTENTION, SUCCEED OR FAIL QUERY CURRENT STATE

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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 »

Slide 10

Slide 10 text

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 »

Slide 11

Slide 11 text

Submitted Paid … Command Event Order State § Customer Details § Order Lines (product + qty) § Shipping Info § Payment Receipt § … Submit Order Pay Order … Order Submitted Order Paid …

Slide 12

Slide 12 text

EVENT-DRIVEN SYSTEM INTERFACE System Command Event Command Event INTERFACE OF THE SYSTEM AS THE SET OF ACCEPTED COMMANDS & QUERIES AND PUBLISHED EVENTS Query Query

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Hexagonal Architecture APPLICATION LOGIC DOMAIN LOGIC INFRASTRUCTURE LOGIC

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

WHY CLOJURE?

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Why Clojure? Drawbacks § Recruitment § Decisions are to be made, nothing is served on a plate (like Spring, .Net) but allows great freedom and power

Slide 19

Slide 19 text

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)

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Rampup for beginners? Easy Difficult when the project is starting as a lot of decisions are not made

Slide 22

Slide 22 text

HOW TO SELL CLOJURE?

Slide 23

Slide 23 text

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.

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

ELECTRE IS RECRUITING J JOBS.ELECTRE.COM