Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building a Bank with Go - QCon London March 2017

Building a Bank with Go - QCon London March 2017

Traditionally applications have been built as monoliths; single applications which become larger and more complex over time, which limit our ability to react to change. An example of this is the banking industry where mergers and acquisitions between banks have lead to a patchwork of different systems & technologies that cost billions of dollars per year to maintain. As a result, the pace of innovation in the banking industry has slowed to a crawl. At Monzo we're building a new kind of bank backed by a microservice platform written in Go. In this talk we'll look at why Go is perfectly suited to this style of architecture, the language features that make it particularly attractive to high volume, low latency, distributed applications, and how easy it is to adopt into existing systems and organisations.

mattheath

March 07, 2017
Tweet

More Decks by mattheath

Other Decks in Programming

Transcript

  1. Building a Bank
    with Go
    Matt Heath, Monzo

    View Slide

  2. Hi, I’m Matt
    @mattheath

    View Slide

  3. View Slide

  4. View Slide

  5. monoliths
    traditional dev

    View Slide

  6. A UK banking licence is authorised by the PRA and
    regulated by the PRA and FCA1, allowing deposit-
    taking and balance sheet lending. Once granted,
    it allows firms to passport across Europe, accessing
    This is followed by a “mobilisation” phase during
    which final capital is raised and IT systems are
    completed, before launching to the public.
    We received a UK banking licence in August 2016!
    FEB
    2015
    JAN
    2016
    JAN
    2017
    MAR FEB FEB
    APR MAR MAR APR MAY JUN JUL
    MAY APR
    JUN MAY
    JUL JUN
    AUG JUL
    SEP AUG
    NOV SEP
    DEC NOV DEC
    PRE APPLICATION APPLICATION MOBILISATION LAUNCH
    LICENCE WITH
    RESTRICTIONS
    50K MAX
    DEPOSIT
    WE ARE
    HERE

    View Slide

  7. View Slide

  8. View Slide

  9. View Slide

  10. View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. ?

    View Slide

  16. Application

    View Slide

  17. Application
    Database

    View Slide

  18. Application
    Database

    View Slide

  19. Application
    Databases

    View Slide

  20. Application
    Databases
    Search

    View Slide

  21. Application
    Databases
    Search
    Caching

    View Slide

  22. Application
    Databases
    Search
    Caching
    CAT GIFS

    View Slide

  23. ALL
    HAIL
    THE
    MONOLITH

    View Slide

  24. View Slide

  25. Application
    Databases
    Search
    Caching
    CAT GIFS

    View Slide

  26. APPLICATION
    Application

    View Slide

  27. View Slide

  28. View Slide

  29. Single Responsibility
    Principle

    View Slide

  30. Bounded Context

    View Slide

  31. Well defined
    Interfaces

    View Slide

  32. View Slide

  33. Why Go?
    Memory Managed
    Statically Typed
    Excellent Concurrency
    Perfect for simple, small, network services

    View Slide

  34. Lightweight
    Concurrency

    View Slide

  35. Goroutines

    View Slide

  36. // Blocking function call
    handleRequest()

    View Slide

  37. // Function runs concurrently
    go handleRequest()

    View Slide

  38. package main
    func main() {
    go handleRequest()
    // …
    }

    View Slide

  39. package main
    func main() {
    go handleRequest()
    // …
    }
    main

    View Slide

  40. package main
    func main() {
    go handleRequest()
    // …
    }
    handleRequest
    main

    View Slide

  41. "Do not communicate by
    sharing memory; instead, share
    memory by communicating."
    - Effective Go

    View Slide

  42. Channels

    View Slide

  43. View Slide

  44. View Slide

  45. View Slide

  46. View Slide

  47. Simplicity

    View Slide

  48. Static Linking
    Stdlib
    etc

    View Slide

  49. 0
    40
    80
    160
    120
    Feb
    2015
    Mar
    2017
    200
    Number of services

    View Slide

  50. View Slide

  51. View Slide

  52. monzo/typhon

    View Slide

  53. Service
    Service

    View Slide

  54. Service
    Service
    Transport

    View Slide

  55. Service
    Service
    Transport
    Service
    Service

    View Slide

  56. Service
    Service
    Transport
    Service
    Service
    Client library
    Server library

    View Slide

  57. Service
    Service Service
    Service
    HTTP
    HTTP

    View Slide

  58. Service Discovery
    Load Balancing
    Timeouts and Expirations
    Retries
    Rate Limiting
    Connection Pooling
    Circuit Breaking
    Failure Detection
    Metrics and Tracing
    Interrupts
    Context Propagation

    View Slide

  59. Service
    Service Service
    Service
    HTTP
    HTTP
    ?

    View Slide

  60. Service
    Service Service
    Service
    HTTP
    HTTP
    linkerd

    View Slide

  61. Service Discovery
    Load Balancing
    Timeouts and Expirations
    Retries
    Rate Limiting
    Connection Pooling
    Circuit Breaking
    Failure Detection
    Metrics and Tracing
    Interrupts
    Context Propagation

    View Slide

  62. Load Balancer

    View Slide

  63. Load Balancer
    HTTP API & Routing Layer

    View Slide

  64. Load Balancer
    HTTP API & Routing Layer
    API

    Service

    View Slide

  65. View Slide

  66. /webhooks —-> Webhook API

    View Slide

  67. Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View Slide

  68. Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View Slide

  69. Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Database

    View Slide

  70. Database
    Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Database

    View Slide

  71. External
    Provider
    Database
    Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Database

    View Slide

  72. type Service func(req Request) Response

    View Slide

  73. router.GET("/", List)
    router.POST("/", Register)
    router.DELETE("/:id", Deregister)

    View Slide

  74. Making our
    service reliable

    View Slide

  75. + =

    View Slide

  76. View Slide

  77. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View Slide

  78. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View Slide

  79. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View Slide

  80. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Slow or

    Errors

    View Slide

  81. Event Driven
    Architecture

    View Slide

  82. Service
    A
    Service
    B
    Load Balancer
    HTTP API & Routing Layer
    API
    Service

    View Slide

  83. API
    Service
    Service
    A
    Service
    B
    Load Balancer
    HTTP API & Routing Layer

    View Slide

  84. API
    Service
    Service
    A
    Service
    B
    Load Balancer
    HTTP API & Routing Layer

    View Slide

  85. API
    Service
    Service
    A
    Service
    B
    Load Balancer
    HTTP API & Routing Layer
    Service
    C
    Service
    D
    Service
    E

    View Slide

  86. Context
    Propagation

    View Slide

  87. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View Slide

  88. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View Slide

  89. 8096820c-3b7b-47ec-bce6-1c239252ab40

    View Slide

  90. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View Slide

  91. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View Slide

  92. package context
    type Context interface {
    Deadline() (deadline time.Time, ok bool)
    Done() <-chan struct{}
    Err() error
    Value(key interface{}) interface{}
    }

    View Slide

  93. package context
    type Context interface {
    Deadline() (deadline time.Time, ok bool)
    Done() <-chan struct{}
    Err() error
    Value(key interface{}) interface{}
    }

    View Slide

  94. package context
    type Context interface {
    Deadline() (deadline time.Time, ok bool)
    Done() <-chan struct{}
    Err() error
    Value(key interface{}) interface{}
    }

    View Slide

  95. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View Slide

  96. api
    api
    api.customer
    api.customer
    service.customer
    service.customer
    SEND
    RECV
    SEND
    RECV
    RECV
    SEND
    RECV
    SEND

    View Slide

  97. api api.customer service.customer
    SEND
    RECV
    SEND
    RECV
    RECV
    SEND
    RECV
    SEND
    phosphor

    View Slide

  98. View Slide

  99. API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns
    API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns

    View Slide

  100. API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns
    API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns

    View Slide

  101. API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns
    API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns

    View Slide

  102. API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns
    API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns

    View Slide

  103. API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns
    API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns

    View Slide

  104. View Slide

  105. API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns
    API card-api card-processing cards transactions balance transaction-enrichment merchant feed-generator feed apns

    View Slide

  106. View Slide

  107. View Slide

  108. Perfect for

    microservice
    architectures

    View Slide

  109. Concurrency:

    Goroutines
    Channels

    View Slide

  110. Small
    Simple
    Easy

    View Slide

  111. Thanks!
    @mattheath
    @monzo

    View Slide