SlideShare a Scribd company logo
Advanced Clojure Microservices
Tobias Bayer Hamburg, 30.09.2016
Clojure, Java, Cloud
tobias.bayer@inovex.de
https://github.com/tobiasbayer
2
Tobias Bayer
Senior Developer / Software Architect
inovex GmbH
3
(defroutes app
(GET "/messages/:name" [name] {:body {:message (str "Hello World" " " name)}})
(route/resources "/")
(route/not-found "Not Found"))
(defn -main [& args]
(run-jetty app {:port 3000 :join? false }))
Microservices with Clojure is easy!
4
~ 20 Microservices
High Availability
Polyglot
About 30% of services in Clojure
Running on AWS
5
Project
6
Resource Modeling
Fault Tolerance
Monitoring and Metrics
Cloudability
...
Real World Problems
7
Resource Modeling with Liberator
8
Resource Modeling with Liberator
9
Decisions
Resource Modeling with Liberator
10
Actions
Resource Modeling with Liberator
11
Handlers
Resource Modeling with Liberator
12
Resource Modeling with Liberator
(defroutes app
(ANY "/api/users" [] r/users)
(ANY "/api/users/:userhandle" [userhandle] (r/user userhandle))
(ANY "/api/authentication" [] r/authentication))
13
Resource Modeling with Liberator
(defresource users
:available-media-types ["application/user-v1+json"]
:allowed-methods [:post]
:malformed? (fn [ctx] (s/validate-user (body ctx)))
:handle-malformed (fn [ctx] (ring-response {:status 400
:body
{:message (str (s/validate-user (body ctx)))})}))
:post! (fn [ctx] (if (user-exists? (body ctx))
{:conflict true}
{:created-entity (create-user (body ctx))}))
:handle-created (fn [ctx] (if (:conflict ctx)
(ring-response {:status 409})
(r/user-output (:created-entity ctx)))))
Circuit Breaker
Netflix
hystrix-clj
clj-http-hystrix
14
Fault Tolerance with Hystrix
(h/add-hook {:hystrix/timeout-ms (:HYSTRIX_TIMEOUT config/settings)
:hystrix/threads (:HYSTRIX_THREADS config/settings)})
15
Fault Tolerance with Hystrix
(defn search-customer [param]
(client/get
(str api-endpoint "/customers?search=" param)
{:content-type :json
:as :json
:hystrix/group-key "customers"
:hystrix/fallback-fn (constantly {:body {:name "Not" :firstname "Found"}})}))
16
Metrics with Prometheus
17
Metrics with Prometheus
18
Metrics with Prometheus
(defroutes app
;; ...
(ANY "/internal/metrics" []
(prometheus/dump-metrics (:registry @metrics/metrics-store))))
(def handler
(-> app
; ...
(prometheus/instrument-handler "" (:registry @metrics/metrics-store))))
19
Metrics with Prometheus
prometheus-clj
(defonce metrics-store (atom (prometheus/init-defaults)))
(defn- register-metrics []
(-> @metrics-store
(prometheus/register-gauge "users" "users_count" "Number of users in DB" ["users_count"])
(prometheus/register-gauge "users" "users_disabled" "Number of disabled users in DB"
["users_disabled"])
(prometheus/register-counter "users" "cache_hits"
"Number of cache hits when requesting a customer" ["cache_hits"])
(prometheus/register-counter "users" "cache_misses"
"Number of cache misses when requesting a customer" ["cache_misses"])))
(defn init []
(reset! metrics-store (register-metrics))
(HystrixPrometheusMetricsPublisher/register (:registry @metrics-store)))
20
Metrics with Prometheus
(defn update-metrics []
(prometheus/set-gauge @metrics-store "users" "users_count" (p/count-users) ["users_count"])
(prometheus/set-gauge @metrics-store "users" "users_disabled"
(p/count-users {:enabled false}) ["users_disabled"]))
(defn inc-cache-hits []
(prometheus/increase-counter @metrics-store "users" "cache_hits" ["cache_hits"] 1))
(defn inc-cache-misses []
(prometheus/increase-counter @metrics-store "users" "cache_misses" ["cache_misses"] 1))
21
Metrics with Prometheus
(defn process-event [event]
(when (= (:eventType event) "SubscriptionChanged")
(log/info "Received event" event)
(handle-subscription-changed-event event)))
(defn start-worker! [fn-processor]
(kinesis/worker! :app (:APP_NAME config/settings)
:stream (:EVENT_STREAM config/settings)
:endpoint (:KINESIS_ENDPOINT config/settings)
:region-name (:AWS_REGION config/settings)
:processor (fn [records]
(doseq [record records]
(process-record record fn-processor)))))
22
Cloudability with Amazonica
AWS Kinesis
23
jobs@inovex.de
www.inovex.de/jobs
+49 721 619 021 50
Wir suchen Verstärkung in den Bereichen
• Digital Consulting
• Web Frontend & Backend
• Replatforming
• Apps & Smart Devices
• Big Data
• Data Science
• Search
• Business Intelligence
• DevOps
• Cloud
• Operations
Hamburg, Köln, München,
Karlsruhe, Pforzheim

More Related Content

PDF
Monitoring Kubernetes with Prometheus
PDF
Data(?)Ops with CircleCI
PDF
Cortex: Horizontally Scalable, Highly Available Prometheus
PDF
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
PDF
Monitoring Kubernetes with Prometheus
PDF
Monitoring Kubernetes with Prometheus
PPTX
Why observability matters - now and in the future (w/guest Grafana)
PPTX
Monitoring Weave Cloud with Prometheus
Monitoring Kubernetes with Prometheus
Data(?)Ops with CircleCI
Cortex: Horizontally Scalable, Highly Available Prometheus
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with Prometheus
Why observability matters - now and in the future (w/guest Grafana)
Monitoring Weave Cloud with Prometheus

What's hot (19)

PDF
Kubernetes and Prometheus
PDF
Know your app: Add metrics to Java with Micrometer | DevNation Tech Talk
PDF
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
PDF
Webhooks do's and dont's: what we learned after integrating +100 APIs - Giuli...
PDF
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...
PDF
NFVO based on ManageIQ - OPNFV Summit 2016 Demo
PDF
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)
PPTX
Ceilometer Updates - Kilo Edition
PDF
Java application monitoring with Dropwizard Metrics and graphite
PPTX
Prometheus for Monitoring Metrics (Fermilab 2018)
PDF
CDK Meetup: Rule the World through IaC
PPTX
The journey to the kubernetes metrics
PDF
stackconf 2021 | Prometheus in 2021 and beyond
PDF
An Introduction to Prometheus
PDF
Monitoring with prometheus at scale
PPTX
Replication - Nick Carboni - ManageIQ Design Summit 2016
PPTX
Airflow at WePay
PDF
Kubernetes extensibility: crd & operators
PDF
Handling Kubernetes Resources
Kubernetes and Prometheus
Know your app: Add metrics to Java with Micrometer | DevNation Tech Talk
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Webhooks do's and dont's: what we learned after integrating +100 APIs - Giuli...
Handle insane devices traffic using Google Cloud Platform - Andrea Ulisse - C...
NFVO based on ManageIQ - OPNFV Summit 2016 Demo
Monitoring Kubernetes with Prometheus (Kubernetes Ireland, 2016)
Ceilometer Updates - Kilo Edition
Java application monitoring with Dropwizard Metrics and graphite
Prometheus for Monitoring Metrics (Fermilab 2018)
CDK Meetup: Rule the World through IaC
The journey to the kubernetes metrics
stackconf 2021 | Prometheus in 2021 and beyond
An Introduction to Prometheus
Monitoring with prometheus at scale
Replication - Nick Carboni - ManageIQ Design Summit 2016
Airflow at WePay
Kubernetes extensibility: crd & operators
Handling Kubernetes Resources
Ad

Viewers also liked (20)

PDF
Moderne App-Entwicklung am Beispiel waipu.tv
PDF
Datenprodukte für Deutschlands größten Fahrzeugmarkt
PDF
Continuous Integration for Fun and Profit
PDF
Erfolgsfaktoren von Datenprodukten
PDF
Gitlab meets Kubernetes
PDF
Stackstorm – Event driven Automation
PDF
Prometheus Monitoring
PDF
Elasticsearch und Big Data - Webinar vom 23.07.2014
PDF
Kubernetes Frankfurt
PDF
OpenStack und Containers
PPTX
Kubernetes Workshop
PDF
Die dunkle Seite der Microservices - und wie du sie besiegen kannst
PPTX
Docker meets Kubernetes
PDF
Dockerized Microservices
PDF
Cloud Wars – what‘s the smartest data platform? Vergleich Microsoft Azure, Am...
PDF
SysDig Metriken zentralisieren
PDF
Automated Application Management with SaltStack
PDF
Monitoring with Graylog - a modern approach to monitoring?
PDF
Sprachsteuerung mit dem Google Assistant – Add a new User Interface to your P...
PDF
Haltet den (Daten-) Dieb! Echtzeiterkennung von Anomalien in Computernetzwerk...
Moderne App-Entwicklung am Beispiel waipu.tv
Datenprodukte für Deutschlands größten Fahrzeugmarkt
Continuous Integration for Fun and Profit
Erfolgsfaktoren von Datenprodukten
Gitlab meets Kubernetes
Stackstorm – Event driven Automation
Prometheus Monitoring
Elasticsearch und Big Data - Webinar vom 23.07.2014
Kubernetes Frankfurt
OpenStack und Containers
Kubernetes Workshop
Die dunkle Seite der Microservices - und wie du sie besiegen kannst
Docker meets Kubernetes
Dockerized Microservices
Cloud Wars – what‘s the smartest data platform? Vergleich Microsoft Azure, Am...
SysDig Metriken zentralisieren
Automated Application Management with SaltStack
Monitoring with Graylog - a modern approach to monitoring?
Sprachsteuerung mit dem Google Assistant – Add a new User Interface to your P...
Haltet den (Daten-) Dieb! Echtzeiterkennung von Anomalien in Computernetzwerk...
Ad

Similar to Advanced Cojure Microservices (20)

PDF
Microservices and the Art of Taming the Dependency Hell Monster
PPTX
Ultimate Guide to Microservice Architecture on Kubernetes
PDF
A Java Developers first Clojure project
PDF
Monitoring Clojure Applications with Prometheus
PDF
Monitoring microservices with Prometheus
PDF
## Introducing a reactive Scala-Akka based system in a Java centric company
PDF
Clojutre Real Life (2012 ClojuTRE Retro Edition)
PDF
Workshop - The Little Pattern That Could.pdf
PDF
Clojure/West 2013 in 30 mins
PDF
Wieldy remote apis with Kekkonen - ClojureD 2016
PDF
Clojure Programming Cookbook Makoto Hashimoto Nicolas Modrzyk
PDF
Building Event Driven (Micro)services with Apache Kafka
PDF
Microservices - opportunities, dilemmas and problems
PDF
Versioning in a microservice architecture
PDF
Clojure High Performance JVM Programming 1st Edition Eduardo Diaz
PDF
Clojure High Performance JVM Programming 1st Edition Eduardo Diaz
PDF
Node.js Microservices Building Scalable and Reliable Applications.pdf
PDF
Java2 days 5_agile_steps_to_cloud-ready_apps
PDF
Monitoring with Prometheus
PDF
ClojureScript in Magento 2 - MageTitansMCR 2017
Microservices and the Art of Taming the Dependency Hell Monster
Ultimate Guide to Microservice Architecture on Kubernetes
A Java Developers first Clojure project
Monitoring Clojure Applications with Prometheus
Monitoring microservices with Prometheus
## Introducing a reactive Scala-Akka based system in a Java centric company
Clojutre Real Life (2012 ClojuTRE Retro Edition)
Workshop - The Little Pattern That Could.pdf
Clojure/West 2013 in 30 mins
Wieldy remote apis with Kekkonen - ClojureD 2016
Clojure Programming Cookbook Makoto Hashimoto Nicolas Modrzyk
Building Event Driven (Micro)services with Apache Kafka
Microservices - opportunities, dilemmas and problems
Versioning in a microservice architecture
Clojure High Performance JVM Programming 1st Edition Eduardo Diaz
Clojure High Performance JVM Programming 1st Edition Eduardo Diaz
Node.js Microservices Building Scalable and Reliable Applications.pdf
Java2 days 5_agile_steps_to_cloud-ready_apps
Monitoring with Prometheus
ClojureScript in Magento 2 - MageTitansMCR 2017

More from inovex GmbH (20)

PDF
lldb – Debugger auf Abwegen
PDF
Are you sure about that?! Uncertainty Quantification in AI
PDF
Why natural language is next step in the AI evolution
PDF
WWDC 2019 Recap
PDF
Network Policies
PDF
Interpretable Machine Learning
PDF
Jenkins X – CI/CD in wolkigen Umgebungen
PDF
AI auf Edge-Geraeten
PDF
Prometheus on Kubernetes
PDF
Deep Learning for Recommender Systems
PDF
Azure IoT Edge
PDF
Representation Learning von Zeitreihen
PDF
Talk to me – Chatbots und digitale Assistenten
PDF
Künstlich intelligent?
PDF
Dev + Ops = Go
PDF
Das Android Open Source Project
PDF
Machine Learning Interpretability
PDF
Performance evaluation of GANs in a semisupervised OCR use case
PDF
People & Products – Lessons learned from the daily IT madness
PDF
Infrastructure as (real) Code – Manage your K8s resources with Pulumi
lldb – Debugger auf Abwegen
Are you sure about that?! Uncertainty Quantification in AI
Why natural language is next step in the AI evolution
WWDC 2019 Recap
Network Policies
Interpretable Machine Learning
Jenkins X – CI/CD in wolkigen Umgebungen
AI auf Edge-Geraeten
Prometheus on Kubernetes
Deep Learning for Recommender Systems
Azure IoT Edge
Representation Learning von Zeitreihen
Talk to me – Chatbots und digitale Assistenten
Künstlich intelligent?
Dev + Ops = Go
Das Android Open Source Project
Machine Learning Interpretability
Performance evaluation of GANs in a semisupervised OCR use case
People & Products – Lessons learned from the daily IT madness
Infrastructure as (real) Code – Manage your K8s resources with Pulumi

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administration Chapter 2
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
AI in Product Development-omnex systems
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Digital Strategies for Manufacturing Companies
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Understanding Forklifts - TECH EHS Solution
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
medical staffing services at VALiNTRY
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
L1 - Introduction to python Backend.pptx
PDF
System and Network Administraation Chapter 3
PDF
Odoo Companies in India – Driving Business Transformation.pdf
Operating system designcfffgfgggggggvggggggggg
Which alternative to Crystal Reports is best for small or large businesses.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Odoo POS Development Services by CandidRoot Solutions
System and Network Administration Chapter 2
Design an Analysis of Algorithms II-SECS-1021-03
AI in Product Development-omnex systems
VVF-Customer-Presentation2025-Ver1.9.pptx
Online Work Permit System for Fast Permit Processing
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Digital Strategies for Manufacturing Companies
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Understanding Forklifts - TECH EHS Solution
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
medical staffing services at VALiNTRY
Wondershare Filmora 15 Crack With Activation Key [2025
L1 - Introduction to python Backend.pptx
System and Network Administraation Chapter 3
Odoo Companies in India – Driving Business Transformation.pdf

Advanced Cojure Microservices

  • 1. Advanced Clojure Microservices Tobias Bayer Hamburg, 30.09.2016
  • 3. 3 (defroutes app (GET "/messages/:name" [name] {:body {:message (str "Hello World" " " name)}}) (route/resources "/") (route/not-found "Not Found")) (defn -main [& args] (run-jetty app {:port 3000 :join? false })) Microservices with Clojure is easy!
  • 4. 4
  • 5. ~ 20 Microservices High Availability Polyglot About 30% of services in Clojure Running on AWS 5 Project
  • 6. 6 Resource Modeling Fault Tolerance Monitoring and Metrics Cloudability ... Real World Problems
  • 12. 12 Resource Modeling with Liberator (defroutes app (ANY "/api/users" [] r/users) (ANY "/api/users/:userhandle" [userhandle] (r/user userhandle)) (ANY "/api/authentication" [] r/authentication))
  • 13. 13 Resource Modeling with Liberator (defresource users :available-media-types ["application/user-v1+json"] :allowed-methods [:post] :malformed? (fn [ctx] (s/validate-user (body ctx))) :handle-malformed (fn [ctx] (ring-response {:status 400 :body {:message (str (s/validate-user (body ctx)))})})) :post! (fn [ctx] (if (user-exists? (body ctx)) {:conflict true} {:created-entity (create-user (body ctx))})) :handle-created (fn [ctx] (if (:conflict ctx) (ring-response {:status 409}) (r/user-output (:created-entity ctx)))))
  • 15. (h/add-hook {:hystrix/timeout-ms (:HYSTRIX_TIMEOUT config/settings) :hystrix/threads (:HYSTRIX_THREADS config/settings)}) 15 Fault Tolerance with Hystrix (defn search-customer [param] (client/get (str api-endpoint "/customers?search=" param) {:content-type :json :as :json :hystrix/group-key "customers" :hystrix/fallback-fn (constantly {:body {:name "Not" :firstname "Found"}})}))
  • 19. (defroutes app ;; ... (ANY "/internal/metrics" [] (prometheus/dump-metrics (:registry @metrics/metrics-store)))) (def handler (-> app ; ... (prometheus/instrument-handler "" (:registry @metrics/metrics-store)))) 19 Metrics with Prometheus prometheus-clj
  • 20. (defonce metrics-store (atom (prometheus/init-defaults))) (defn- register-metrics [] (-> @metrics-store (prometheus/register-gauge "users" "users_count" "Number of users in DB" ["users_count"]) (prometheus/register-gauge "users" "users_disabled" "Number of disabled users in DB" ["users_disabled"]) (prometheus/register-counter "users" "cache_hits" "Number of cache hits when requesting a customer" ["cache_hits"]) (prometheus/register-counter "users" "cache_misses" "Number of cache misses when requesting a customer" ["cache_misses"]))) (defn init [] (reset! metrics-store (register-metrics)) (HystrixPrometheusMetricsPublisher/register (:registry @metrics-store))) 20 Metrics with Prometheus
  • 21. (defn update-metrics [] (prometheus/set-gauge @metrics-store "users" "users_count" (p/count-users) ["users_count"]) (prometheus/set-gauge @metrics-store "users" "users_disabled" (p/count-users {:enabled false}) ["users_disabled"])) (defn inc-cache-hits [] (prometheus/increase-counter @metrics-store "users" "cache_hits" ["cache_hits"] 1)) (defn inc-cache-misses [] (prometheus/increase-counter @metrics-store "users" "cache_misses" ["cache_misses"] 1)) 21 Metrics with Prometheus
  • 22. (defn process-event [event] (when (= (:eventType event) "SubscriptionChanged") (log/info "Received event" event) (handle-subscription-changed-event event))) (defn start-worker! [fn-processor] (kinesis/worker! :app (:APP_NAME config/settings) :stream (:EVENT_STREAM config/settings) :endpoint (:KINESIS_ENDPOINT config/settings) :region-name (:AWS_REGION config/settings) :processor (fn [records] (doseq [record records] (process-record record fn-processor))))) 22 Cloudability with Amazonica AWS Kinesis
  • 23. 23
  • 24. jobs@inovex.de www.inovex.de/jobs +49 721 619 021 50 Wir suchen Verstärkung in den Bereichen • Digital Consulting • Web Frontend & Backend • Replatforming • Apps & Smart Devices • Big Data • Data Science • Search • Business Intelligence • DevOps • Cloud • Operations Hamburg, Köln, München, Karlsruhe, Pforzheim