Architecting a Modern Financial Institution SOUTHEAST BRAZIL REGION - - PowerPoint PPT Presentation

architecting a modern financial institution
SMART_READER_LITE
LIVE PREVIEW

Architecting a Modern Financial Institution SOUTHEAST BRAZIL REGION - - PowerPoint PPT Presentation

Architecting a Modern Financial Institution SOUTHEAST BRAZIL REGION FROM SPACE CREDIT CARD September 2014 GROWING QUICKLY IN A COMPLEX DOMAIN # of clients (M) 10.5 M 20 Credit Card 3,0 Unique applications Deploys per day 2.6 M 120 2,3


slide-1
SLIDE 1

Architecting a Modern Financial Institution

SOUTHEAST BRAZIL REGION FROM SPACE
slide-2
SLIDE 2

CREDIT CARD

September 2014

slide-3
SLIDE 3 0,8 1,5 2,3 3,0 Set-14 Jan-15 Mai-15 Set-15 Jan-16 Mai-16 Set-16 Jan-17 Mai-17 Set-17

GROWING QUICKLY IN A COMPLEX DOMAIN

# of clients (M) Credit Card

Unique applications

10.5M

Countries

198

Customers

2.6M

Purchases

262M

Deploys per day

20

Microservices

120

Engineers

105

slide-4
SLIDE 4

IMMUTABLE THEMES FROM OUR STACK

LISP hosted on the JVM Functional (opinionated), immutable data structures Simple, concise, fast, concurrent Tight REPL feedback cycles Gradual typing (schemas)

CLOJURE DATOMIC CLOUD KAFKA

slide-5
SLIDE 5

IMMUTABLE THEMES FROM OUR STACK

for your data

CLOJURE DATOMIC CLOUD KAFKA

Accumulate-only Reified ACID transactions, preserve what changed when Query using data structures (Datalog) Cloud native with integrated caching and scalable reads

slide-6
SLIDE 6

IMMUTABLE THEMES FROM OUR STACK

Immutable, persistent, partitioned log Logical decoupling between services Temporal decoupling, useful for asymmetric workloads Fault isolation and recovery (circuit breakers, dead letters) Financial batch jobs expressed as a streams of messages

CLOJURE DATOMIC CLOUD KAFKA

slide-7
SLIDE 7

IMMUTABLE THEMES FROM OUR STACK

Infra as code (AWS) Immutable upon provisioning (Docker) Blue-Green deploys at service and company level Kubernetes for speed and scalability

CLOJURE DATOMIC CLOUD KAFKA

slide-8
SLIDE 8

FUNCTIONAL BENEFITS

HIRING

POSITIVE SELF SELECTION 1-MONTH RAMP

COMPLEXITY

SMALL, PURE FUNCTIONS STRAIGHTFORWARD TO UNTANGLE

CONSISTENCY

COMPOSING A SMALL NUMBER OF IDIOMATIC LANGUAGE FEATURES

Nubank HQ São Paulo, Brazil

slide-9
SLIDE 9

CREDIT CARD ARCHITECTURE

Greenfield MVP

Anti-fraud Collections General Ledger Phone + Chat Authorizer Securitization ETL Credit Scoring Customer Acquisition (KYC) Credit Limits Logistics Card Origination Billing Installment Purchases FX Backoffice (CRM) Notification Chargeback Bill Pay Infosec Rewards + Merchants Marketing

slide-10
SLIDE 10

BANK ACCOUNT

October 2017

13
slide-11
SLIDE 11

CORE BANKING + CREDIT CARD ARCHITECTURE

INFRASTRUCTURE

Rewards + Merchants Marketing Investment Management Treasury + Risk Realtime Transfers Lending + Interest Rates Tax Anti-fraud Collections General Ledger Phone + Chat Authorizer Securitization ETL Customer Acquisition (KYC) Credit Scoring Logistics Card Origination Billing Installment Purchases Credit Limits FX Backoffice (CRM) Notification Chargeback Bill Pay Infosec

slide-12
SLIDE 12

PURCHASE AUTHORIZATION

Customer Acquisition (KYC) Credit Scoring Logistics Anti-fraud Card Origination Authorizer Billing Installment Purchases Credit Limits Investment Management FX Collections Treasury + Risk Rewards + Merchants Realtime Transfers Backoffice (CRM) Lending + Interest Rates Notification General Ledger Securitization Marketing Chargeback Tax Bill Pay Phone + Chat Infosec ETL

INFRASTRUCTURE

slide-13
SLIDE 13

MERCHANT ACQUIRER NETWORK ISSUER

PURCHASE AUTHORIZATION VALUE CHAIN

CUSTOMER

slide-14
SLIDE 14

NETWORK ISSUER

ISSUER AUTHORIZATION

slide-15
SLIDE 15

MASTERCARD INTERFACE DEVICE AUTHORIZER

ISSUER AUTHORIZATION

1

Establish a connection

2

Receive authorization requests

slide-16
SLIDE 16

MASTERCARD INTERFACE DEVICE AUTHORIZER

ISSUER AUTHORIZATION: ISO-8583

ISO-8583 Binary Message

HARDWARE SECURITY MODULE

slide-17
SLIDE 17
  • bject PANMappingFileD {

import scala.language.reflectiveCalls val codec: Codec[SE33Subfield] = discriminated[SE33Subfield].by(intPadded(2)) .typecase(1, llvar(str).as[AccountNumberIndicator]) .typecase(2, llvar(intString(intPadded(2))).as[AccountNumber]) .typecase(3, llvar(yearMonth).as[ExpirationDate]) .typecase(4, llvar(str).as[ProductCode]) .typecase(5, llvar(intPadded(2)).as[TokenAssuranceLevel]) .typecase(6, llvar(intString(intPadded(2))).as[TokenRequestorID]) .typecase(7, llvar(intString(intPadded(2))).as[PANAccountRange]) }

SCODEC BINARY PARSER FOR ISO-8583

slide-18
SLIDE 18

BRAND INTERFACE DEVICE AUTHORIZER

ISSUER AUTHORIZATION: REQUIREMENTS

ISO-8583 Binary Message

HARDWARE SECURITY MODULE (HSM)

1.Highly Available
 2.Physical Infrastructure

slide-19
SLIDE 19

AUTHORIZER SERVICE LAYOUT

fraud fraud HSM HSM crypto crypto

  • Small set of highly available

services

  • Co-located with the MasterCard

devices in the same datacenters

  • Isolated: transaction

authorization hot path does not need communication with the cloud

  • Active-active disaster recovery

(not shown)

Thrift Finagle Server authorizer authorizer authorizer authorizer Finagle Client router ISO 8583 router Proprietary protocol

slide-20
SLIDE 20

“neverland”

(nubank datacenter)

kafka

“the real world”

(AWS VPC)

100+ microservices

KAFKA AS THE BRIDGE BETWEEN ENVIRONMENTS

slide-21
SLIDE 21

1 2 3 4 …

Kafka Topic Partition

KAFKA-BASED LOG/SNAPSHOT

AWS Service

1

Publish

2

Authorizer consumes

  • ffset

2

4

Generates a snapshot

3

Snapshot service consumes snapshotter

5

New authorizer started

6

Reads Snapshot

7

Consumes from snapshot offset

slide-22
SLIDE 22 0 % 0,35 % 0,7 % 1,05 % 1,4 % 2016-07 2016-09 2016-11 2017-01 2017-03 2017-05 2017-07 0 % 20 % 40 % 60 % 80 % 2017-03 2017-04 2017-05 2017-06 2017-07 2017-08 2017-09

% stand-in % fraud capture % fraud precision cutover cutover

DRAMATIC IMPROVEMENTS IN RELIABILITY AND FRAUD

slide-23
SLIDE 23

DOUBLE ENTRY ACCOUNTING

Customer Acquisition (KYC) Credit Scoring Logistics Anti-fraud Card Origination Authorizer Billing Installment Purchases Credit Limits Investment Management FX Collections Treasury + Risk Rewards + Merchants Realtime Transfers Backoffice (CRM) Lending + Interest Rates Notification General Ledger Securitization Marketing Chargeback Tax Bill Pay Phone + Chat Infosec ETL

INFRASTRUCTURE

slide-24
SLIDE 24

Interest Chargebacks Payments Currencies Purchases

Should we…

authorize a purchase? block a card? charge interest?

BUSINESS LOGIC DEPENDS ON DATA ACROSS MANY SERVICES

Double Entry

slide-25
SLIDE 25

DOUBLE ENTRY: THE MODEL

ENTRY CREDIT BOOK ACCOUNT DEBIT BOOK ACCOUNT

$

= 𝚻

BALANCE

$

The sum of all credits and debits for one book-account is its balance A customer’s balance sheet is a cumulative function of their entire history

slide-26
SLIDE 26

DOUBLE ENTRY: THE RULEBOOK

ENTRY CREDIT BOOK ACCOUNT DEBIT BOOK ACCOUNT

$

NEW-PURCHASE NEW-PAYMENT …

ENTRY 2 CREDIT BOOK ACCOUNT DEBIT BOOK ACCOUNT

$

ENTRY 3 CREDIT BOOK ACCOUNT DEBIT BOOK ACCOUNT

$

MOVEMENT

slide-27
SLIDE 27

(def unsettled-purchase [ {:entry/debit-account :book-account-type.asset/unsettled :entry/credit-account :book-account-type.liability/unsettled-counterparty :entry/amount #'transaction-amount :entry/post-date #'produced-date} {:entry/debit-account :book-account-type.liability/current-limit-counterparty :entry/credit-account :book-account-type.asset/current-limit :entry/amount #'transaction-amount :entry/post-date #’produced-date} ])

DOUBLE ENTRY: EXAMPLE MOVEMENT

slide-28
SLIDE 28
  • rdering matters (i.e. movements are not commutative)


late arriving events (e.g. a payment was made 3 days ago)
 fixing invariants write throughput

DOUBLE ENTRY: CHALLENGES

slide-29
SLIDE 29

(def loss-property (prop/for-all [adjs (gen/vector (gen/one-of [gen-adjustment gen-payment gen-tx]) 1 10) initial-state (gen/such-that (comp not #{:late :pre-loss} :state) rbh/initial-state-gen) loss-event (gen/tuple (gen/no-shrink (gen/elements #{:pre-loss :credit-loss :id-fraud-loss :fraudster})) (tg/make-generator LocalDateTime) (tg/make-generator LocalDate))] (check-properties adjs initial-state loss-event)))

DOUBLE ENTRY: GENERATIVE TESTING OF INVARIANT

slide-30
SLIDE 30
  • rdering actually matters (i.e. movements are not commutative)


late arriving events (e.g. a payment was made 3 days ago)
 fixing invariants write throughput

DOUBLE ENTRY: CHALLENGES

slide-31
SLIDE 31

SHARDED, FAULT TOLERANT INFRASTRUCTURE

Customer Acquisition (KYC) Credit Scoring Logistics Anti-fraud Card Origination Authorizer Billing Installment Purchases Credit Limits Investment Management FX Collections Treasury + Risk Rewards + Merchants Realtime Transfers Backoffice (CRM) Lending + Interest Rates Notification General Ledger Securitization Marketing Chargeback Tax Bill Pay Phone + Chat Infosec ETL

INFRASTRUCTURE

slide-32
SLIDE 32 0,8 1,5 2,3 3,0 Set-14 Jan-15 Mai-15 Set-15 Jan-16 Mai-16 Set-16 Jan-17 Mai-17 Set-17

SCALING BOTTLENECKS

# of clients (M) Credit Card

  • 1. database throughput limits

required throttling writes

  • 2. batch job latency impacting

customer experience


slide-33
SLIDE 33

Need to partition the workload Customer data is spread across services Interactions between customers are minimal Safe to partition the user base

SCALING PLAN

slide-34
SLIDE 34

Database writes were the worst bottleneck Option: horizontally partition each database Change every service to route queries and writes to the appropriate shard

db shard s0 db shard s1 db shard s2

OPTION #1: PARTITION SERVICE DATABASES

backend service

slide-35
SLIDE 35

Enormous effort to change every service Doesn’t address non-db bottlenecks Risks intermingling data infrastructure code with business logic

OPTION #1: PROBLEMS

slide-36
SLIDE 36

OPTION #2: SCALABILITY UNITS

SERVICE 1 SERVICE 2 SERVICE 3 SERVICE 1 SERVICE 2 SERVICE 3 SERVICE 1 SERVICE 2 SERVICE 3

shard S0 shard S1 shard s2

. . .

slide-37
SLIDE 37

OPTION #2: SCALABILITY UNITS + GLOBAL ROUTING

SERVICE 1 SERVICE 2 SERVICE 3 SERVICE 1 SERVICE 2 SERVICE 3

shard S1 shard s2

SERVICE 4 SERVICE 5

global

SERVICE 6

purchase deposit

SERVICE 1 SERVICE 2 SERVICE 3

shard S0

slide-38
SLIDE 38

OPTION #2: HYPERMEDIA FOR INTERACTIONS

SERVICE 1 SERVICE 2 SERVICE 3

shard S1

SERVICE 4 SERVICE 5

global

SERVICE 6

login

{"_links": {"account": “https://s1-service2…”}} {"_links": {"account": “https://s1-service3…”}}

slide-39
SLIDE 39

SCALING LESSONS LEARNED

works in practice, but difficult to move incrementally in that direction

SCALABILITY UNITS WORK

sharding was a complex project exponential growth defies intuition: use real growth models for planning

START EARLY

provide critical flexibility for shard routing

MESSAGING AND HYPERMEDIA

made this process much more tractable

AUTOMATED IMMUTABLE INFRA

business logic may create hot spots reactivated old prospects overcrowded s0

BEWARE HOTSPOTS

it’s devilishly difficult (we avoided it, mostly)

SPLITTING EXISTING DATA

slide-40
SLIDE 40

FAULT TOLERANCE PATTERNS

Simple patterns for fault isolation and recovery

PRODUCER CONSUMER

1

Publish

2

Consume

TOPIC DEADLETTER-TOPIC

MORTICIAN

4

Persist

5

Republish

DEADLETTERS CIRCUIT BREAKERS

SERVICE

1

Consume

3

Circuit breaker trips!

3

Exception! Produce deadletter

2

Outbound fails

4

Pause consuming

slide-41
SLIDE 41

ETL + THE ANALYTICAL ENVIRONMENT

Customer Acquisition (KYC) Credit Scoring Logistics Anti-fraud Card Origination Authorizer Billing Installment Purchases Credit Limits Investment Management FX Collections Treasury + Risk Rewards + Merchants Realtime Transfers Backoffice (CRM) Lending + Interest Rates Notification General Ledger Securitization Marketing Chargeback Tax Bill Pay Phone + Chat Infosec ETL

INFRASTRUCTURE

slide-42
SLIDE 42

01 NOV 10:00

Robot 437aae3 approves R$3K limit

01 NOV 11:00

Mastercard purchase, Starbucks, R$100

09 NOV 08:00

Support agent increases limit to R$5K

15 NOV 15:00

Customer blocks card

15 NOV 17:05

Customer joins waiting list for a card

DATOMIC PRIMER: EVENTS OVER TIME

slide-43
SLIDE 43

01 NOV 10:00 01 NOV 11:00 09 NOV 08:00 15 NOV 15:00 15 NOV 17:05

[<customer> :customer/id #uuid “b2c90…” 1] [<account> :account/customer <customer> 2] [<account> :account/limit 3000 2] [<card> :card/account <account> 2] [<card> :card/status :card.status/active 2] [<purchase> :purchase/card <card> 3] [<purchase> :purchase/amount 100 3] [<purchase> :purchase/merchant “Starbucks” 3] [<account> :account/limit 5000 4] [<account> :account/limit 3000 4] [<card> :card/status :card.status/blocked 5] [<card> :card/status :card.status/active 5]

DATOMIC PRIMER: FACTS OVER TIME

entity attribute value tx

slide-44
SLIDE 44

“The DAG”

Pure functions (Scala SQL) Take datasets, return dataset Metadata (schema, partitions,

path on S3, performance)

Runs on Spark

DB1 Log S0 DB1 Log S1 DB2 Log S0 Dataset Series

Kafka topics Datomic DB logs EXTRACTOR Change capture Chunking Format conversion Auto-correcting

S3

contract 1 contract 2 dataset 1 dataset 2 policy model

Datomic and Kafka log extraction feeding our data lake (S3) in real time Analytical schemas (“contracts”) generated from Datomic entities Shards recombined into a logical table-per-entity incrementally

EXTRACT, TRANSFORM, LOAD

slide-45
SLIDE 45

ETL EXAMPLE: CONTRIBUTION MARGIN

from double entry from ERP are we making money?

slide-46
SLIDE 46

REALTIME TRANSFERS

Customer Acquisition (KYC) Credit Scoring Logistics Anti-fraud Card Origination Authorizer Billing Installment Purchases Credit Limits Investment Management FX Collections Treasury + Risk Rewards + Merchants Realtime Transfers Backoffice (CRM) Lending + Interest Rates Notification General Ledger Securitization Marketing Chargeback Tax Bill Pay Phone + Chat Infosec ETL

INFRASTRUCTURE

slide-47
SLIDE 47
slide-48
SLIDE 48

REALTIME MONEY TRANSFER

1

Transfer request

In-shard Transfers

3

Initiate transfer out

Investments

2

Liquidate investment

Global Transfers

4

Process transfer (global)

Ledger

4

Debits + credits

SPB Client

EXTERNAL

5

Kafka <> SOAP

5

INTERNAL

Shard routing

RSFN (XML) SITRAF (TED)

Hundreds

  • f Brazilian

banks

6

Realtime gross settlement

slide-49
SLIDE 49

BRAZILIAN PAYMENTS SYSTEM

Hub and spoke model for national payments

SPB Client

5

Kafka <> SOAP

RSFN (XML) SITRAF (TED)

Hundreds

  • f Brazilian

banks

6

Realtime gross settlement

Real time gross, irrevocable and unconditional settlement of unlimited amounts ~R$1 trillion (US$300B) transferred per day 06:30 - 18:30 business days Proprietary XML protocol, IBM MQ Series messaging

See: https://www.bcb.gov.br/Pom/Spb/Ing/Introduction.asp

slide-50
SLIDE 50

DOMAIN MODEL SUMMARY

Customer Acquisition (KYC) Credit Scoring Logistics Anti-fraud Card Origination Authorizer Billing Installment Purchases Credit Limits Investment Management FX Collections Treasury + Risk Rewards + Merchants Realtime Transfers Backoffice (CRM) Lending + Interest Rates Notification General Ledger Securitization Marketing Chargeback Tax Bill Pay Phone + Chat Infosec ETL

INFRASTRUCTURE

slide-51
SLIDE 51

We’re hiring

https://nubank.workable.com

São Paulo, Brazil

slide-52
SLIDE 52

We’re hiring

https://nubank.workable.com

Berlin, Germany

slide-53
SLIDE 53

THANK YOU!

slide-54
SLIDE 54

BACKUP

SOUTHEAST BRAZIL REGION FROM SPACE
slide-55
SLIDE 55

EXTERNAL

  • Client authentication (mutual TLS)
  • authorizing new device with reputation

score

  • Immutable infrastructure
  • Short-lived instances
  • No mutations
  • Bootstrap service identity from instance

profiles using IAM

  • Uniformity of service architecture enables

rapid patching

KEY SECURITY DECISIONS

INTERNAL

  • Auto-revoke of access scopes
  • Operational scopes are short lived
  • Customer contact enables access
  • Employee access bootstrapped from Google

OAuth, 2FA + Yubikeys required

  • Realtime monitoring of security events
  • Cloudtrail, Slack, Lambdas for fine-grained
  • perational access control
  • Internal red team / incident response team
slide-56
SLIDE 56 1,25 2,5 3,75 5 13 26 39 52 65 78 91 104117130143156169182195208221234247260273286299312325338351364377390403416429442455468481494507520533546559572585598611624

2016-02 2016-06 2016-09 2016-12 2017-03 2017-06 2017-09

GROWING ORGANICALLY THROUGH REFERRALS

Each customer we book leads to 3-4 new leads

# of Leads Sample Cohorts - Days after release