Road Trip To Component

Preview:

Citation preview

Road Trip to Component

Marketa Adamova

NOMNOM INSIGHTS

Technical challenges• Import large amounts of data in various

formats

• Process, analyse and store data

• Present data to user

• Fast search and stats on data

Reasons for change

• Missing NLP libraries

• Better data storage

• Performance issues

• Prototype app

Taking the Clojure turn

Why Clojure?• JVM

• Java Interop

• Concurrent processing

• Data representation

• Fun to write

Lukasz Korecki (CTO at NomNom)

“We moved to Clojure because of JVM and we stayed for everything else.”

Main road blockers

• Correct JVM setup

• Application structure

• Managing shared application state

How to structure Clojure application

Organising Clojure code

• Namespaces

• Extract code to libraries

• Protocols

Protocol & types

• Mechanism for abstraction

• Polymorphism

• Boundaries between subsystems

Handling state in Clojure

Mutable state• https://clojure.org/about/state

• State = value associate with identity at given time

• Memory cache, concurrent programming, …

• Atoms, refs, agents

Shared state

• Accessible from various namespaces

• Open connections and channels

• Global accessible configuration

• Mutability not required during runtime

Application configuration

• Function to load env variable

• Configuration in single atom

Application configuration

• Function to load env variable

• Configuration in single atom

• Config library

• Mount

• Component

Stuart Sierra’s Component

What is ‘Component’

• managing lifecycle and dependencies of components with runtime state

• db access, external API services, web server

• system of components

How it solves our problem

• Enforcing structure in code

• State defined in single place

• Better visibility of system

Testing

• Mock components

• Integration tests for complex flow

• E2E test

REPL interaction

• Define development system

• Multiple systems in single JVM

• No need to restart REPL

Production• Avoid accessing production system !!

• Visualise system & strong subsystem boundaries

• Debugging

• Add ad hoc components when required

The bad parts …• “all or nothing”

• Failures during system startup

• Trying to use “wrappers”

• Integration with other libraries

• OO approach

End of journey

Resources

https://clojure.org/indexhttps://github.com/stuartsierra/componenthttps://github.com/tolitius/mounthttp://www.joyofclojure.comhttp://thinkrelevance.com/blog/2013/11/07/when-should-you-use-clojures-object-oriented-featureshttps://purelyfunctional.tv/issues/clojure-gazette-180-how-do-you-structure-your-apps/https://cb.codes/organizing-clojure-projects-and-libraries/

… and lots of other Clojure talks, articles and discussions

Questions?