SLIDE 1 Unibet.com Architecture
Open Source at Unibet.com: 10x scalability at half the cost stefan.norberg@unibet.com @stnor
SLIDE 2
About the speaker
SLIDE 3
Unibet Open Source strategy
SLIDE 4
- Open source software and open standards should
always be our first choice
- Avoid vendor lock-in - software we use should have a
right-to-use license without any cost attached
SLIDE 5
- Commercial, proprietary software need to show
exceptional business value (over Free solutions) in order to be considered
- Contribute to the community by buying support from
companies backing FOSS solutions or paying for product improvements
SLIDE 6 Betting Engine Messaging Customers Async Betting API Web CMS REST API:s Partners & Affiliates Payment Banners
Single-sign-on
Bonus System Wallet System Customer System
Browser Flash/Flex DDos Protection Content Deliver Networks Fan-out Push Servers Poker Casino Bingo
SLIDE 7 Betting Engine Messaging Customers Async Betting API Web CMS REST API:s Partners & Affiliates Payment Banners
Single-sign-on
Bonus System Wallet System Customer System
Browser Flash/Flex DDos Protection Content Deliver Networks Fan-out Push Servers
SLIDE 8 Unibet in numbers
- 100% online - www.unibet.com
- 30+ web sites in 27 languages
- Gross win: 250 million dollars / year
- “Technical” growth is >100% / year
SLIDE 9
SLIDE 10
SLIDE 11
SLIDE 12
SLIDE 13
SLIDE 14
SLIDE 15
SLIDE 16
Why is this hard?
SLIDE 17
Because users are growing impatient
SLIDE 18 2006: 4 seconds
Source: Juniper Research
SLIDE 19 2009: 2 seconds
Source: Forrester Research
SLIDE 20 Two main challenges
- Latency - data too far away from where it’s
needed
- Bottlenecks - resource contention
SLIDE 21
Avg 40 ms RTT
SLIDE 22 Meet Kevin
- Kevin is a customer to the candy store
- Kevin wants to buy 40 pcs for his allowance
- Kevin has extremely small pockets (they
- nly fit one piece of candy)
- He also wants to buy two chocolate bars
and one bubble gum
- The candy store is far far away from Kevin’s
house
SLIDE 23
SLIDE 24
Idea #1 Sell bags of candy
(Caveat: no bars or bubblegums in bags!)
SLIDE 25
SLIDE 26
The bag is a big JS file
SLIDE 27
The bag is a big CSS file
SLIDE 28
The bag is a CSS image sprite*
SLIDE 29
/4.9.3/images/uskin1/uspritesheadertabs.png blackTab
SLIDE 30 The 100% optimized e-commerce web page: 4 requests
HTML
Conn 1
CSS
JS Conn 2
250 ms 30 ms 250 ms
IMG
30 ms
Total time: 530 ms
SLIDE 31 Some real world data
- amazon.com: 57 requests (6)
- ebay.com: 41 requests (4)
- unibet.com: 41 requests (1)
SLIDE 32
Ouch.
SLIDE 33
Idea #2 Sell bags on street corners
(Caveat: no bars or bubblegums in bags!)
SLIDE 34
SLIDE 35
There are many street corners
SLIDE 36
Street corners are very near all customers
SLIDE 37
The street corner is a Content Delivery Network node
SLIDE 38
SLIDE 39 GOOD SPOT
35 ms avg latency
SLIDE 40 BAD SPOT
70 ms avg latency
SLIDE 41 BAD SPOT
Bandwidth Latency Redundancy Pricing
SLIDE 42 Tune tune tune the front-end!
- 80-90% of the end-user response time is
spent downloading and processing all the components in the page
- Rewrote and optimized all our front-end
code (XHTML, CSS, JS)
- Implemented image spriting and fixed other
issues with cache headers etc
SLIDE 43 Tune tune tune the front-end!
- Use best practice to optimize your front-
end (YSlow, Page Speed etc)
- Progressive rendering is key
- Improve performance by having objects
served close to the user
SLIDE 44
http://www.webpagetest.org/
SLIDE 45 How we do it
YSlow and Pagespeed guidelines
- Be close to your users - use a Content
Delivery Network (CDN)
- Prepend CDN proxy name to all static
files: /foo/bar -> http://cdn.com/foo/bar
- Set a one year cache-time (no 304:s)
- Version your static content
- Stripe objects over several CNAMES
SLIDE 46 NOT SO BAD SPOT
15 ms avg latency 10 ms avg latency 10 ms avg latency
SLIDE 47
- By using a CDN we serve our users quickly
from anywhere in the world
- Capacity is not an issue
- We have cut our delivery costs to 25%
- Use several CDN vendors for load balancing /
redundancy
SLIDE 48
Next steps...
SLIDE 49 Live Betting data distribution
“Who gets the next corner”, “who scores the next goal” etc
- 10000:s of real-time clients need price
updates almost every second
- 20 concurrent games
- 10+ offers within one game
- Product growth 60-80% per year
SLIDE 51 Fan-out Server Fan-out Server
Betting Engine
SLIDE 52 Betting Engine RabbitMQ
Rabbit MQ
Kaazing
Rabbit MQ
Kaazing
- End-to-end messaging
- RabbitMQ
- Kaazing Enterprise Gateway
- Google Protocol Buffers
SLIDE 53 RabbitMQ
- Free Open Source and Open Standards
protocol (AMQP)
- Highly available, highly scalable (Erlang/OTP)
- Excellent & friendly support available
SLIDE 54 Kaazing
- Open Source and Open Standards protocol
(HTML5 WebSockets)
- Supported AMQP clients for Flex, browers
- Connection offloading
- Great at overcoming last mile hurdles
(firewalls, proxies, browsers)
- Excellent & friendly support available
SLIDE 55 Protocol Buffers
- Flexible, efficient, automated mechanism for
serializing (binary)
- Schema support (.proto files)
- Language neutral (we use Java to Actionscript)
- Invented and used by Google
- Open Sourced in July 2008
SLIDE 56 Java/ Spring
Fan-out node
AS3
Betting Engine Live Betting Client
RabbitMQ RabbitMQ Kaazing
Protobufs/AMQP
SLIDE 57
Let’s get back to the Candy store...
SLIDE 58 Datacenter
- Ok, the candy delivery problem is solved!
- However, we cannot serve the customers
chocolate and bubble gum quickly enough
- Queues are building up due to our
bottlenecks
SLIDE 59
SLIDE 60
The chocolate bar is a cacheable read
SLIDE 61
The bubble gum is a non-cacheable read or a write
SLIDE 62
The candy store checkout is an app server
SLIDE 63
The bubble gum machine is a database system
SLIDE 64
Example #1 More hardware! (and sw licenses)
SLIDE 65
Kids are invading our store...
SLIDE 66
SLIDE 67
SLIDE 68
SLIDE 69
SLIDE 70
SLIDE 71
paying per core is paying for peaks... ...is not acceptable?
Food for thought
SLIDE 72
SLIDE 73
SLIDE 74
You cannot buy a product to solve this problem
SLIDE 75
Need to rearchitect!
SLIDE 76
Example #2 Near-cache
SLIDE 77 Terracotta
- Network Attached Memory
- Extends the Java threading model across
JVM:s
- In-memory speed access to data
- Fully coherent, with stored to disk
guarantees
- Writes are sent as deltas across nodes
SLIDE 78 Keep data stored/cached where it’s needed for processing
Event Repository Bet Offer Repository Live Bets
Terracotta L2
Betting Engine Betting Engine Betting Engine
... Oracle (MySQL) JVM Heap “L1”
write-behind
SoR
Eventually consistent Reporting/ Legacy
SLIDE 79 Keep data stored/cached where it’s needed for processing
Event Repository Bet Offer Repository Live Bets
Terracotta L2
Betting Engine Betting Engine Betting Engine
... Oracle (MySQL)
write-behind
update
JVM Heap “L1” SoR
Reporting/ Legacy
SLIDE 80 Terracotta
- L2 server can become bottleneck
- Shard (free) or stripe ($$$)
SLIDE 81
Example #3 Offload reads to separate systems
SLIDE 82 Bet History
MySQL
History Server History Server
...
R R R Event Repository Bet Offer Repository Live Bets
Terracotta L2
Betting Engine Betting Engine Betting Engine
... Oracle (MySQL)
Backoffice
Settle Bet
SLIDE 83
Example #4 Affinity + multi master replication
SLIDE 84 Customer System Customer System Customer System Customer System
cus-client.jar user1 user2 user3
LDAP LDAP LDAP
cus-client.jar
LDAP
data center 2
user4
data center 1
SLIDE 85
Example #5 Partition the data to scale writes
SLIDE 86 Bet History routing
MySQL
History Server History Server
...
S1 S2 S3 Live Bets C C C
done quickly
- More than 10000 writes / s
- Scale out by using multiple
MySQL instances
SLIDE 87
SLIDE 88
Combining the pieces
SLIDE 89 Betting Engine AMQP Broker (RabbitMQ)
Geo-distributed Fan-out Push Servers (Kaazing) Browser Betting Client Flash Betting Client HTML
Betting History Database (MySQL)
Shared memory for events, bet
(Terracotta)
Betting Engine Betting Engine Account Servers
write-behind write-behind
price updates and replies commands payouts Betting API History API sharded with local MySQL Settled bets 100% read Live data
SLIDE 90 Recap: Two main challenges
- Latency - data too far away from where it’s
needed
- Bottlenecks - resource contention
SLIDE 91 Recipes used at Unibet
- Optimize your web apps!
- Get rid of static object traffic
- Move web data closer to customers (CDN)
- Last-mile fan-out messaging
information delivery
SLIDE 92 Recipes used at Unibet
- Move data to business logic
- Read-only farms
- Multi-master replication for read-mostly
data
in the data center
SLIDE 93
Open Source Software and Services is used by Unibet extensively in mission critical applications because...
SLIDE 94
...we are convinced it’s better and more cost effective!
SLIDE 95 Thanks!
(we’re hiring)
@stnor stefan.norberg@unibet.com stnor.wordpress.com www.linkedin.com/in/stnor
SLIDE 96
Backup slides
SLIDE 97 DDoS resilience
- Outsourced DNS
- DDoS protection service
SLIDE 98
SLIDE 99
SLIDE 100 GRE tunnels
Unibet is here Unibet is here Unibet is here