6/18/14 Billing & Payments Engineering Meetup I

112
Billing & Payments Engineering Meetup June 18 th , 2014

Transcript of 6/18/14 Billing & Payments Engineering Meetup I

Page 1: 6/18/14 Billing & Payments Engineering Meetup I

Billing & PaymentsEngineering Meetup

June 18th, 2014

Page 2: 6/18/14 Billing & Payments Engineering Meetup I

• Mathieu Chauvin – NetflixValidating Payment Information

• Taylor Wicksell – NetflixFlexible Billing Integrations Using Events

• Jean-Denis Greze – DropboxMistakes (and Wins) Building Payments at Dropbox

• Anthony Zacharakis – LumosityBilling Migrations: Maintaining Your (Data) Sanity

• Alec Holmes – SquareScaling Merchant Payouts at Square

=== Break ===• Paul Huang – SurveyMonkey

Billing Globalization and Auto Renewal Optimization• Emmanuel Cron – Google Wallet

Moving from SE to Host Card Emulation• Feifeng Yang / Michael Chen – Electronic Arts

Ecommerce at EA• Krishnan Sridhar – LinkedIn

Real-Time Analytics and Smart Routing

Page 3: 6/18/14 Billing & Payments Engineering Meetup I

Validating Payment Information

Mathieu Chauvin@matchauvin – linkedin/matchauvin

Page 4: 6/18/14 Billing & Payments Engineering Meetup I

Signing-Up for Netflix

• Subscription Based• 30 Days Free Trial• Payment Information

Collection

Page 5: 6/18/14 Billing & Payments Engineering Meetup I

• Pro Forma• Luhn Check (Mod10)• Card Type vs Card# RegEx• Authorization / Reversal

Payment Validation 101

Page 6: 6/18/14 Billing & Payments Engineering Meetup I

But Wait! You Can Do More!

Page 7: 6/18/14 Billing & Payments Engineering Meetup I

Authorization Amount

• $0.00, $1.00, or Full Price Authorization• Don’t Forget the Reversal!• Constraints by Country or by Card Type

Page 8: 6/18/14 Billing & Payments Engineering Meetup I

Response Types

• Hard Declines• Soft Declines

Page 9: 6/18/14 Billing & Payments Engineering Meetup I

MCC

• What is an MCC?• Figure out the Best MCC Fit

Page 10: 6/18/14 Billing & Payments Engineering Meetup I

BINs

• What is a BIN?• Card Types: Credit, Debit, Prepaids• What About Non-Reloadable Prepaid Cards?

Page 11: 6/18/14 Billing & Payments Engineering Meetup I

Forking Traffic

• Do You Use Several Payment Processors?• Why Don’t You Test Which One Performs

Better?

Page 12: 6/18/14 Billing & Payments Engineering Meetup I

Use Cases

• Sign-Up• Updating Payment Information• Returning Customer

Page 13: 6/18/14 Billing & Payments Engineering Meetup I

Country Specific Behavior

• Adapt To Your Market

Page 14: 6/18/14 Billing & Payments Engineering Meetup I

The Feedback Loop

• A/B Tests• Analyze, Project & Evaluate Risks• Test Again

Page 15: 6/18/14 Billing & Payments Engineering Meetup I

Conclusion

• Try Everything• Build Your Application Dynamically• The Feedback Loop!

Thank You!

Page 16: 6/18/14 Billing & Payments Engineering Meetup I

Flexible Billing Integrations Using Events

Taylor Wicksell

Page 17: 6/18/14 Billing & Payments Engineering Meetup I

The Billing Team

• Signups/Cancellations• Recurring Billing• Price and Tax Calculations• Discounts / Gifts• Financial Reporting

Page 18: 6/18/14 Billing & Payments Engineering Meetup I

Current Architecture

• Netflix Data Center• Batch Processing and

Customer Requests• Oracle (Single-Master)• Data driven

Page 19: 6/18/14 Billing & Payments Engineering Meetup I

Cloud Migration - Primary Goals

• Join Netflix in the Cloud• High Availability• Multi-Regional Active/Active• Scalability

Page 20: 6/18/14 Billing & Payments Engineering Meetup I

New Design• Amazon EC2• Multi-Regional

• Cassandra• Event Driven

Page 21: 6/18/14 Billing & Payments Engineering Meetup I

Order Flow

Page 22: 6/18/14 Billing & Payments Engineering Meetup I

Cross-Cutting Concerns

• Publishing Data To Interested Parties– Hold Messaging– Financial Reporting

• Metrics/Analytics• Velocity Checks• Debugging

Page 23: 6/18/14 Billing & Payments Engineering Meetup I

Wiretap to Common Event Pipeline

Page 24: 6/18/14 Billing & Payments Engineering Meetup I

Common Event Pipeline

Current Implementation• SQS Entry Point• Custom routing service• Custom code for each

endpoint integration• Weak ordering of events

Future Implementation• Suro / Kafka Entry Point• Configurable Routing and

Transformation• Pluggable endpoint

integration• Option for strong ordering

of events

Page 25: 6/18/14 Billing & Payments Engineering Meetup I
Page 26: 6/18/14 Billing & Payments Engineering Meetup I

Sting – Broad Analytics

Page 27: 6/18/14 Billing & Payments Engineering Meetup I

Druid – Event Aggregation Metrics

Page 28: 6/18/14 Billing & Payments Engineering Meetup I

ElasticSearch – Event Level Debugging

Page 29: 6/18/14 Billing & Payments Engineering Meetup I

Mistakes (and Wins) Building Payments At Dropbox

Jean-Denis Grèze & Dan WheelerJune 18th, 2014

Page 30: 6/18/14 Billing & Payments Engineering Meetup I

Backend Tips• Not about increasing conversion• Not about pricing• Not about plan and feature

optimizations• Not about upselling• Not about consumer SaaS at scale• Not about self-serve in

SMB/SME/Enterprise

Page 31: 6/18/14 Billing & Payments Engineering Meetup I

Pains of Scaling Payments• Thousands of customers to millions of

customers• SMB to Enterprise

– Custom flows!• International expansion

– Fraud– New payment methods (delayed

settlements)– Different price points

Page 32: 6/18/14 Billing & Payments Engineering Meetup I

Out Of The Dark Ages• For a long time, only 0.5 engineers

worked on payments and billing• March 2013: consult w/ leading

payment engineers, PMs and executives on how to build an amazing payments team– 15+ in 1 year

Page 33: 6/18/14 Billing & Payments Engineering Meetup I

Advice• Build a payments + billing backend

that is:– Flexible

• Migrations (sadface)• Requirements will change – often

– Auditable• Always know why and state changed

– Append Only• Never lose data

Page 34: 6/18/14 Billing & Payments Engineering Meetup I

Team Ca$h

Page 35: 6/18/14 Billing & Payments Engineering Meetup I

Team Ca$h• Engineers

– Some finance background– A lot of systems/analytics background

• PMs– Some finance/accounting background– Some product/marketing background

• Advisors– Payments experts– Tight feedback loop w/ finance

• Designers

Page 36: 6/18/14 Billing & Payments Engineering Meetup I

Migrations

Page 37: 6/18/14 Billing & Payments Engineering Meetup I

Migrations• You will have to migrate

– 3rd-party vaulting to self vaulting– New markets = new processors– If you are a growing company, your internals will

require migrations• Stakes are high

– Double-billing? Forgetting to charge some users? Inadvertently moving users from one pricing category to another?

• Old way:– Ad hoc– Tons of tests

Page 38: 6/18/14 Billing & Payments Engineering Meetup I

I. Leverage Existing Code: Equivalence

• Write equivalence between old and new implementations (database, API, 3rd party providers, tests, etc.)

• Run everything through both systems at once, with equivalence being tested

• Every step of the way check that equivalence relations hold (e.g., old-style invoice has a new-style invoice equivalent)

• Turn off old system when everything works for X amount of time

Page 39: 6/18/14 Billing & Payments Engineering Meetup I

Migration Pro-Tip• If you can migrate in both

directions at will on a per-endpoint basis, your life will be awesome and people will love you.

Page 40: 6/18/14 Billing & Payments Engineering Meetup I

Moneytree

Page 41: 6/18/14 Billing & Payments Engineering Meetup I

Logging• Dark Ages = tons of logging

• Very comprehensive, but ad-hoc = too much effort to re-create state

• Human error

Page 42: 6/18/14 Billing & Payments Engineering Meetup I

II. Automated Logging• Automatically log

– Any DB write (graph, relational, etc.)– Any 3rd party API call (and some internal calls

like email)• Pre-log

– Any incoming 3rd party payload• Can recreate past actions if we introduced a

regression• LOG A REASON (and code version)

– 1 year is a long time

Page 43: 6/18/14 Billing & Payments Engineering Meetup I

Automated Logging =

Time Machine

Page 44: 6/18/14 Billing & Payments Engineering Meetup I

Not too much data• Dropbox = large scale for SaaS• Hundreds of millions of users

(provisioning is hard)• Tons of data, but still payments data

<< file storage data– Although we do have the benefits of

amazing infrastructure

Page 45: 6/18/14 Billing & Payments Engineering Meetup I

III. States, Not Deltas• Generally # states << # deltas• States

– Pro 100 + Packrat– DfB + Harmony Enabled

• Deltas– Add 5 licenses, 6 licenses, etc.– Add 20 licenses and switch from monthly to

yearly• Use states and let the system figure out

how to get from start to end

Page 46: 6/18/14 Billing & Payments Engineering Meetup I

IV. Possibility & Transitions Use Same Code Paths

• No difference between:– entity.is_valid_transition(end_state)– entity.perform_transition(end_state)

• Except that writes are turned off for the former.

• No change for “is something possible” logic to be different than “do the thing” logic.

Page 47: 6/18/14 Billing & Payments Engineering Meetup I

States Are Nicetransition_space = MoneytreeTransitionsSpace.build_cross_product( entity=me, gateways=ALL_GATEWAYS, plans=[Pro100, Pro200, Pro500, DfB, DfBTrial], schedules=[Monthly, Yearly], currencies=ALL_CURRENCIES, features=ALL_FEATURES, tax_profile=[NoTax, SimpleTax, ComplexTax],)# …If transition_space.supports(FEATURE_PACKRAT): # …

Page 48: 6/18/14 Billing & Payments Engineering Meetup I

Write Protection• Seems dumb, but need to be careful

not to accidentally change values in payments world. Have clearly-defined code paths that can touch state, talk to 3rd party components, etc.

Page 49: 6/18/14 Billing & Payments Engineering Meetup I

V. One More Lesson• Payments + Billing != Finance• Business requirements don’t always

translate to what’s best/easiest in the world of accounting. You need to flexibly work in both worlds – can’t risk the user experience to make your finance dep’t happy (and vice-versa)

• Get a great PM

Page 50: 6/18/14 Billing & Payments Engineering Meetup I

VI. Why Payments Are Cool?• Infrastructure?

– Payments service– Provisioning service

• Product?– Upsells? (+50% increase in revenue per user)– Gating features?

• Product Infrastructure!– Build a successful structure by emphasizing

hard problems in both worlds!

Page 51: 6/18/14 Billing & Payments Engineering Meetup I
Page 52: 6/18/14 Billing & Payments Engineering Meetup I

Now + The Future• Other Cool Projects

– ML for risk/anomaly detection (e.g., for payment methods that don’t settle immediately)

– Price AB testing (*)– Cross-platform upsell framework

• Questions?– [email protected][email protected]

• Hiring– Get in touch!

Page 53: 6/18/14 Billing & Payments Engineering Meetup I

Team Ca$h

Page 54: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Data SanityA short treatise on

rebuilding a payment system

Anthony Zacharakis
Also additional dev friction
Page 55: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

the background

Page 56: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Circa 2012Decided to rewrite our payment system

Page 57: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

ReasonsOld payment system has a lot of limitations

Page 58: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Payment system limitations• Hard to add additional gateways• Models don’t reflect business

reality• Not built for reporting• Code is brittle

Page 59: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

3 months later…

Page 60: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

New payment system features• Trivial to add new payment

methods• Subscriptions are the core

model• Built with reporting in mind• Separate, well encapsulated

library

Page 61: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Works like a charm!

Page 62: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

wait… just one problem

Page 63: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Having two parallel payment systems is

not sustainable

Surprise!

As it turns out

Page 64: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Just deprecate the old one

Page 65: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Just deprecate the old one• Don't migrate anyone, let old

users churn out naturally (will take forever)

Page 66: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Just deprecate the old one• Don't migrate anyone, let old

users churn out naturally (will take forever)

• Migrate everyone, but only most critical/current subscription info (loses history)

Page 67: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Just deprecate the old one• Don't migrate anyone, let old

users churn out naturally (will take forever)

• Migrate everyone, but only most critical/current subscription info (loses history)

• Migrate everyone + full history (tricky, lots of edge cases)

Page 68: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

so, what’d we choose?

(drum roll)

Page 69: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

We decided to migrate everyone and their entire

billing history

Page 70: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Why?One systemOne history

One source of truth

Page 71: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Page 72: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

enter the sanity check

Page 73: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

enter the sanity checkJust make a sanity check before and after the migration to ask questions

Page 74: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

enter the sanity checkBoth models should answer certain questions the same way, e.g:• How much did the user pay for a

subscription?• How many total transactions did the user

make?• Was auto-renewal enabled on X date?

Page 75: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

class SanityCheck Methods = [:subscriber?, :transaction_count] # etc.

def initialize(record) @record = record @before_values = SanityCheck.values(record) end

def self.values(record) Methods.map { |m| [m, record.send(m)] }.to_h endend

enter the sanity check

Page 76: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

class SanityCheck ...

def check @after_values = SanityCheck.values(record) @diff = diff(@before_values, @after_values) end

def diff(a, b) a.delete_if { |k, v| b[k] == v } .merge!(b.dup.delete_if { |k, v| a.has_key?(k) }) endend

enter the sanity check

Page 77: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

enter the sanity checkUser.each do |user| sanity_check = SanityCheck.new(user) user.migrate! sanity_check.check if sanity_check.diff.any? # sanity check failed -- log an error, rollback, etc. raise ActiveRecord::Rollback else # woo hoo, success! user.update_attributes(:migrated => true) endend config/initializers/

user_auth.rb

Page 78: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

the result

Page 79: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

A resounding success!

the result

Page 80: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

(Mostly)

the result

Page 81: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Did not work in all cases●Payment system behavior changed

over time

Page 82: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Did not work in all cases●Payment system behavior changed

over time●Some concepts did not map

between systems

Page 83: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Handling the edge cases●Replayed history as it would play out

in the new system●Still kept most critical information

the same (e.g. transaction timestamps)

Page 84: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

Skip ahead to todayMigrated 99.9994%* of all our users successfully to the new system

*The remaining .0006% live on for business, not technical reasons

Page 85: 6/18/14 Billing & Payments Engineering Meetup I

Lumos Labs, Inc.

ThanksAnthony Zacharakis

[email protected]@azacharax

Page 86: 6/18/14 Billing & Payments Engineering Meetup I

Scaling Merchant Payouts at Square

Alec Holmes

Page 87: 6/18/14 Billing & Payments Engineering Meetup I

‣ Infrastructure team that moves money

‣ Card processing (money in)‣ Settlements (money out)

Payments Team

Page 88: 6/18/14 Billing & Payments Engineering Meetup I

‣ Monolithic Rails app‣ Database storage and IO limits‣ Controls around accounting data

Disaster Ahead

Page 89: 6/18/14 Billing & Payments Engineering Meetup I

Monorail

Database

Payments Bills

Deposits

Where We Started

Page 90: 6/18/14 Billing & Payments Engineering Meetup I

Ledger

Database

Payments Bills

DepositsMonorail

Database

API

Current System

Page 91: 6/18/14 Billing & Payments Engineering Meetup I

Challenge:Migrating Live Data

‣ Stricter money-moving event model‣ Same event streams to all systems‣ Smart queueing of events

Page 92: 6/18/14 Billing & Payments Engineering Meetup I

Challenge:Moving to APIs

‣ Replace direct data access with API calls

‣ Hadoop for analytics queries

Page 93: 6/18/14 Billing & Payments Engineering Meetup I

That's it. All pennies accounted for!

Page 94: 6/18/14 Billing & Payments Engineering Meetup I
Page 95: 6/18/14 Billing & Payments Engineering Meetup I

Billing Globalization and Auto-Renewal Optimization

• Paul Huang• Engineering Manager• SurveyMonkey• June 18th, 2014

Page 96: 6/18/14 Billing & Payments Engineering Meetup I

Our mission is to help people make

better decisions

Page 97: 6/18/14 Billing & Payments Engineering Meetup I

We help people get answers to their questions

customers create surveys distribute to others recipients respond customers analyze and gain insight

Page 98: 6/18/14 Billing & Payments Engineering Meetup I

Our customers have invented many ways to use our tool

98

Page 99: 6/18/14 Billing & Payments Engineering Meetup I

90MUnique visitors every month

17K New sign-ups

daily “SurveyMonkey turns online

surveys into a hot business.”

“ Start-up companies using ‘freemium’ business models, including SurveyMonkey, are thriving as the cost of computer power and storage falls.”

One of the hottest startups to watch. 2.4M

Survey responses are generated daily

SurveyMonkey is the world’s largest survey company

Page 100: 6/18/14 Billing & Payments Engineering Meetup I

Billing Globalization

In 2010...

Currencies:1 currency (USD).

Payment Methods: Credit Card, Invoice.

Pricing: one price per package.

Revenue: $ MM

Page 101: 6/18/14 Billing & Payments Engineering Meetup I

Billing Globalization

In 2014...

Currencies: 39 international currencies.

Payment Methods: Credit Card, PayPal, Debit Card, Bank Transfer, iTunes, Invoice.

Pricing: each package with different price per currency, multiple prices allowed for price testing.

Revenue: $$$$ MM

Page 102: 6/18/14 Billing & Payments Engineering Meetup I

Auto-Renewal Optimization

Retry Logic: retry failed payments at different intervals, ~60% retry success rate

Account Updater: get users’ updated credit card data (number / expiration date) before next renewal date, ~4% users at 96% success rate

Immediate Renewal: charge pending invoices when users update payment accounts, ~4% retry success rate improvement

Page 103: 6/18/14 Billing & Payments Engineering Meetup I

TheRoad

Ahead

Page 104: 6/18/14 Billing & Payments Engineering Meetup I

Upcoming Billing Projects in 2014

VAT 2015: preparations for VAT rule changes in Europe in 2015

Brazil Payment Processing: set up local entity, integrate with a new Payment Service Provider in Brazil

Continue Improving Retry Logic: increase retry frequencies

Page 105: 6/18/14 Billing & Payments Engineering Meetup I

The End (BTW, we’re hiring…)

Page 106: 6/18/14 Billing & Payments Engineering Meetup I

E-commerce at EA

Feifeng Yang / Michael ChenTech Lead Payment / Software Engineer @ Electronic Arts

Page 107: 6/18/14 Billing & Payments Engineering Meetup I

E-commerce platform• Power hundreds of games,

millions of gamers• FIFA• Battlefield• SimCity, Sims• Origin• Play4free, etc

• Foundation services to EA game studios

Page 108: 6/18/14 Billing & Payments Engineering Meetup I

Foundation services• EA Origin Store: http://store.origin.com• Payment Gateway• Ewallet System• Billing System• Subscription System• Risk and Fraud System• Shopping Cart System• Catalog System• Rating and Revenue Allocation System

Page 109: 6/18/14 Billing & Payments Engineering Meetup I

Foundation services

Page 110: 6/18/14 Billing & Payments Engineering Meetup I

Billing and Payment• Preorder and subscription• Package goods• EA Ewallet: million of transactions per day• Product types: base game, bundles, DLC, PDLC, etc• Payment methods

• Card processing• PayPal• Mobile billing• Other ~30 local payment methods.

Page 111: 6/18/14 Billing & Payments Engineering Meetup I

Technologies• RESTful API framework: SimpleHttpServer (home grown, ported from open source project SimpleWeb)

• Application: OSGI, Use Equinox as OSGI container• Datastore: MySQL + Sharding, Oracle (to be retired)• Cache: Coherence cache (to be retired); Memcached• Security: OAuth 2.0, CAS 2.0 (Central Authentication SSO)

• JMS messaging: TIBCO, iHUB.

Page 112: 6/18/14 Billing & Payments Engineering Meetup I

112

* Jun 1st to Oct 17th