Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

18.09.2017 Clojure Meetup - ZALANDOS APPROACH TO MICROSERVICES IN CLOJURE

602 views

Published on

Dmitrii Balakhonskii from Zalando in Berlin held this presentation on "Zalandos approach to microservices in Clojure" on the CLOJURE HAMBURG MEETUP in the Zalando adtech lab Office on 18th September 2017

Published in: Engineering
  • Be the first to comment

  • Be the first to like this

18.09.2017 Clojure Meetup - ZALANDOS APPROACH TO MICROSERVICES IN CLOJURE

  1. 1. Zalando’s approach to microservices in Clojure Dmitrii Balakhonskii
  2. 2. 2 About me Dmitrii Balakhonskii • programming since 1999 • into Clojure since 2013 • in Zalando since 2015 https://github.com/dryewo
  3. 3. 3 Microservices ● relatively small ● communicating via REST ● independently deployable ● different languages, different data storages
  4. 4. 4 Overview
  5. 5. 5 Authentication Identity and Access Management (IAM) as a service ● gives out and rotates tokens ● checks validity of tokens
  6. 6. 6 https://github.com/zalando-stups/swagger1st resources/api.yaml: paths: '/hello': get: operationId: my.app/get-hello responses: default: description: Say hello my/app.clj: (defn get-hello [_ params request] {:status 200 :body "Hello”}) RESTful API
  7. 7. 7 Load balancing
  8. 8. 8 DB Schema Migrations https://flywaydb.org/ resources/db/migrations/V1__create_users_table.sql: CREATE TABLE users ( id UUID PRIMARY KEY, name TEXT NOT NULL ); resources/db/migrations/V2__add_user_address.sql: ALTER TABLE users ADD COLUMN address TEXT;
  9. 9. 9 State Management (defstate db :start {:datasource (start-connection)} :stop (.stop (:datasource db)} MountStuart Sierra’s Component (defrecord DB [datasource] component/Lifecycle (start [this] (assoc this :datasource (start-connection)) (stop [this] (when datasource (.stop datasource)) (assoc this :datasource nil)) (defn make-db [] (map->DB {}))
  10. 10. 10 DB Access https://www.hugsql.org/ resources/db/queries.sql: -- :name get-users :? :* SELECT id, address FROM users ORDER BY name LIMIT :limit; users.clj: (def-db-fns "db/queries.sql") (get-users db {:limit 10})
  11. 11. 11 Hystrix is a library from Netflix. https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-clj (defcommand cmd-get-users [db params] (get-users db params)) (cmd-get-users db {:limit 10}) External services
  12. 12. 12 Other aspects? https://12factor.net/ ● configuration through environment variables ● logs to STDOUT ● REPL-driven development

×