Slide 1

Slide 1 text

RAILSCLUB 2015 Microservices in Gett Andrey Deryabin

Slide 2

Slide 2 text

Team Lead @brainopia @razum2um @nebolsin @ssdany Andrey Deryabin

Slide 3

Slide 3 text

Taxi Beauty Home Services Food Delivery 10 million users 32 cities

Slide 4

Slide 4 text

— James Hughes “Microservice Architecture is an architectural concept that aims to decouple a solution by decomposing functionality into discrete services”

Slide 5

Slide 5 text

— Sam Newman “Microservices are small, autonomous services that work together”

Slide 6

Slide 6 text

Teamwork Communication Shared Code Fault Tolerance Authentication/Authorization Logging/Auditing Testing Configuring

Slide 7

Slide 7 text

Communication HTTP REST JSON

Slide 8

Slide 8 text

Shared code

Slide 9

Slide 9 text

Don’t Repeat Yourself vs Service Isolation

Slide 10

Slide 10 text

git ‘https://link_to_repo.git' do gem 'gett-config' gem 'gett-env' end

Slide 11

Slide 11 text

Authentication

Slide 12

Slide 12 text

Single sign-on Integration with OKTA (authorization) Two-Factor authentication Requirements

Slide 13

Slide 13 text

Auth Service

Slide 14

Slide 14 text

redirect 302 with SAML request JWT Auth Service Client Service SAML response

Slide 15

Slide 15 text

Versioning/Auditing

Slide 16

Slide 16 text

A B C D

Slide 17

Slide 17 text

Distributed Transaction

Slide 18

Slide 18 text

Flat transaction Nested Transaction

Slide 19

Slide 19 text

One Phase Commit Two Phase Commit

Slide 20

Slide 20 text

Two phase commit 1. Voting Phase • Coordinator sends a can_commit? request to all participants • Each participant votes YES/NO to coordinator 2. Completion Phase • Coordinator collects votes and makes the decision • YES Participants wait for a commit! or abort! request.

Slide 21

Slide 21 text

A B C D

Slide 22

Slide 22 text

A B C D check check check

Slide 23

Slide 23 text

A B C D check check check

Slide 24

Slide 24 text

A B C D check check check

Slide 25

Slide 25 text

A B C D check check check confirmation confirmation confirmation

Slide 26

Slide 26 text

A B C D check check check confirmation confirmation confirmation

Slide 27

Slide 27 text

A B C D check check check confirmation confirmation confirmation

Slide 28

Slide 28 text

A B C D check check check confirmation confirmation confirmation

Slide 29

Slide 29 text

Copy On Write

Slide 30

Slide 30 text

Fault Tolerance

Slide 31

Slide 31 text

Millions of API requests per day

Slide 32

Slide 32 text

Lots of servers

Slide 33

Slide 33 text

Hundreds of dependencies

Slide 34

Slide 34 text

— Mia Hamm “Failure happens all the time. It happens every day in practice. What makes you better is how you react to it”

Slide 35

Slide 35 text

Release it!

Slide 36

Slide 36 text

Resilience patterns Use Timeouts Bulkheads Fail Fast Circuit Breaker

Slide 37

Slide 37 text

Circuit Breaker

Slide 38

Slide 38 text

Closed Closed Half open Timeout reset Success Failure Threshold reached Success

Slide 39

Slide 39 text

Circuit Breaker require 'stoplight' stoplight = Stoplight('ping') { ping 'railsclub.ru' } stoplight.run # => true stoplight.color # => “green" ############## stoplight.run # => false stoplight.color # => "red"

Slide 40

Slide 40 text

Testing

Slide 41

Slide 41 text

Manual tests Automated Tests

Slide 42

Slide 42 text

Testing workflow Local Server Staging Server QA Server Production

Slide 43

Slide 43 text

RSpec Lurker Capybara

Slide 44

Slide 44 text

Lurker https://github.com/razum2um/lurker

Slide 45

Slide 45 text

Validating JSON Schema Documentation UI for live testing (Swagger integration)

Slide 46

Slide 46 text

# spec/requests/users_spec.rb it "lists users", :lurker do get "/api/v1/users.json" end

Slide 47

Slide 47 text

// lurker/api/v1/users-GET.json.yml --- description: user listing prefix: users management requestParameters: description: '' type: object responseCodes: - status: 200 successful: true description: '' responseParameters: type: array items: description: '' type: object additionalProperties: false required: [] properties: id: description: '' type: integer example: 1 name: description: '' type: string example: razum2um extensions: method: GET path_info: "/api/v1/users.json" path_params: action: index controller: api/v1/users query_params: limit: '1'

Slide 48

Slide 48 text

Failure/Error: post :create [...] Lurker::ValidationError: Request - The property '#/' contains additional properties ["social_network"] outside of the schema when none are allowed in schema file:///.../lurker/api/v1/users- POST.json.yml# Response - The property '#/user/last_sign_in_at' of type String did not match the following type: null in schema file:///.../lurker/api/v1/users-POST.json.yml#

Slide 49

Slide 49 text

Configuring when provisioning

Slide 50

Slide 50 text

Configuring on the fly (without restart/redeploy) Distributed configuring No syncronization lack

Slide 51

Slide 51 text

— zookeeper.apache.org “ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed synchronization, and providing group services”

Slide 52

Slide 52 text

http://bit.ly/Lurker http://bit.ly/ReleaseIt http://bit.ly/BuildingMicroservices http://jwt.io/ http://gett.com http://zookeeper.org

Slide 53

Slide 53 text

Thanks! aderyabin @aderyabin @evilmartians evilmartians.com [email protected]