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 full-size slide

  2. Hi, I’m Matt
    @mattheath

    View full-size slide

  3. monoliths
    traditional dev

    View full-size slide

  4. 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 full-size slide

  5. Application
    Database

    View full-size slide

  6. Application
    Database

    View full-size slide

  7. Application
    Databases

    View full-size slide

  8. Application
    Databases
    Search

    View full-size slide

  9. Application
    Databases
    Search
    Caching

    View full-size slide

  10. Application
    Databases
    Search
    Caching
    CAT GIFS

    View full-size slide

  11. ALL
    HAIL
    THE
    MONOLITH

    View full-size slide

  12. Application
    Databases
    Search
    Caching
    CAT GIFS

    View full-size slide

  13. APPLICATION
    Application

    View full-size slide

  14. Single Responsibility
    Principle

    View full-size slide

  15. Bounded Context

    View full-size slide

  16. Well defined
    Interfaces

    View full-size slide

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

    View full-size slide

  18. Lightweight
    Concurrency

    View full-size slide

  19. // Blocking function call
    handleRequest()

    View full-size slide

  20. // Function runs concurrently
    go handleRequest()

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  25. Static Linking
    Stdlib
    etc

    View full-size slide

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

    View full-size slide

  27. monzo/typhon

    View full-size slide

  28. Service
    Service

    View full-size slide

  29. Service
    Service
    Transport

    View full-size slide

  30. Service
    Service
    Transport
    Service
    Service

    View full-size slide

  31. Service
    Service
    Transport
    Service
    Service
    Client library
    Server library

    View full-size slide

  32. Service
    Service Service
    Service
    HTTP
    HTTP

    View full-size slide

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

    View full-size slide

  34. Service
    Service Service
    Service
    HTTP
    HTTP
    ?

    View full-size slide

  35. Service
    Service Service
    Service
    HTTP
    HTTP
    linkerd

    View full-size slide

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

    View full-size slide

  37. Load Balancer

    View full-size slide

  38. Load Balancer
    HTTP API & Routing Layer

    View full-size slide

  39. Load Balancer
    HTTP API & Routing Layer
    API

    Service

    View full-size slide

  40. /webhooks —-> Webhook API

    View full-size slide

  41. Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View full-size slide

  42. Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View full-size slide

  43. Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Database

    View full-size slide

  44. Database
    Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Database

    View full-size slide

  45. External
    Provider
    Database
    Auth

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Database

    View full-size slide

  46. type Service func(req Request) Response

    View full-size slide

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

    View full-size slide

  48. Making our
    service reliable

    View full-size slide

  49. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View full-size slide

  50. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View full-size slide

  51. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API

    View full-size slide

  52. Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Webhook

    Service
    Load Balancer
    HTTP API & Routing Layer
    Webhook

    API
    Slow or

    Errors

    View full-size slide

  53. Event Driven
    Architecture

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  58. Context
    Propagation

    View full-size slide

  59. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View full-size slide

  60. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View full-size slide

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

    View full-size slide

  62. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View full-size slide

  63. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  67. api
    api
    api.customer
    api.customer
    service.customer
    service.customer

    View full-size slide

  68. api
    api
    api.customer
    api.customer
    service.customer
    service.customer
    SEND
    RECV
    SEND
    RECV
    RECV
    SEND
    RECV
    SEND

    View full-size slide

  69. api api.customer service.customer
    SEND
    RECV
    SEND
    RECV
    RECV
    SEND
    RECV
    SEND
    phosphor

    View full-size slide

  70. 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 full-size slide

  71. 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 full-size slide

  72. 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 full-size slide

  73. 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 full-size slide

  74. 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 full-size slide

  75. 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 full-size slide

  76. Perfect for

    microservice
    architectures

    View full-size slide

  77. Concurrency:

    Goroutines
    Channels

    View full-size slide

  78. Small
    Simple
    Easy

    View full-size slide

  79. Thanks!
    @mattheath
    @monzo

    View full-size slide