OSS at Unibet.key - Jfokus
OSS at Unibet.key - Jfokus
OSS at Unibet.key - Jfokus
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Unibet</strong>.com ArchitectureOpen Source <strong>at</strong> <strong>Unibet</strong>.com:10x scalability <strong>at</strong> half the coststefan.norberg@unibet.com@stnor
About the speaker
<strong>Unibet</strong> Open Sourcestr<strong>at</strong>egy
• Open source software and open standards shouldalways be our first choice• Avoid vendor lock-in - software we use should have aright-to-use license without any cost <strong>at</strong>tached
• Commercial, proprietary software need to showexceptional business value (over Free solutions) in orderto be considered• Contribute to the community by buying support fromcompanies backing F<strong>OSS</strong> solutions or paying forproduct improvements
CustomersPartners &Affili<strong>at</strong>esBannersBrowserFlash/FlexContent Deliver NetworksFan-out Push ServersDDos ProtectionSingle-sign-onPaymentWeb CMSREST API:sPoker Casino BingoAsync Betting APIMessagingCustomerSystemWalletSystemBonusSystemBettingEngine
CustomersPartners &Affili<strong>at</strong>esBannersBrowserFlash/FlexContent Deliver NetworksFan-out Push ServersDDos ProtectionSingle-sign-onPaymentWeb CMSREST API:sAsync Betting APIMessagingCustomerSystemWalletSystemBonusSystemBettingEngine
<strong>Unibet</strong> in numbers• 100% online - www.unibet.com• 30+ web sites in 27 languages• Gross win: 250 million dollars / year• “Technical” growth is >100% / year
Why is this hard?
Because users aregrowing imp<strong>at</strong>ient
2006:4 secondsSource: Juniper Research
2009:2 secondsSource: Forrester Research
Two main challenges• L<strong>at</strong>ency - d<strong>at</strong>a too far away from where it’sneeded• Bottlenecks - resource contention
Avg 40 ms RTT
Meet Kevin• Kevin is a customer to the candy store• Kevin wants to buy 40 pcs for his allowance• Kevin has extremely small pockets (theyonly fit one piece of candy)• He also wants to buy two chocol<strong>at</strong>e barsand one bubble gum• The candy store is far far away from Kevin’shouse
Idea #1Sell bags of candy(Cave<strong>at</strong>: no bars or bubblegums in bags!)
The bag is a big JS file
The bag is a big CSS file
The bag is a CSS imagesprite*
4.9.3/images/uskin1/uspritesheadertabs.pngblackTab
The 100% optimized e-commerce web page:4 requestsConn 1250 ms 30 msHTMLCSSConn 2250 msJSTotal time: 530 ms30 msIMG
Some real world d<strong>at</strong>a• amazon.com: 57 requests (6)• ebay.com: 41 requests (4)• unibet.com: 41 requests (1)
Ouch.
Idea #2Sell bags on streetcorners(Cave<strong>at</strong>: no bars or bubblegums in bags!)
There are many streetcorners
Street corners are very nearall customers
The street corner is aContent Delivery Networknode
GOOD SPOT35 msavg l<strong>at</strong>ency
BAD SPOT70 msavg l<strong>at</strong>ency
BAD SPOTBandwidthL<strong>at</strong>encyRedundancyPricing
Tune tune tune thefront-end!• 80-90% of the end-user response time isspent downloading and processing all thecomponents in the page• Use best practice to optimize your frontend(YSlow, Page Speed etc)• Next step to improve performance is totweak delivery
How we do it• Be close to your users - use a ContentDelivery Network (CDN)• Prepend CDN proxy name to all st<strong>at</strong>icfiles: /foo/bar -> http://cdn.com/foo/bar• Set a one year cache-time (no 304:s)• Version your st<strong>at</strong>ic content• Stripe objects over several CNAMES
15 msavg l<strong>at</strong>ency10 msavg l<strong>at</strong>ency10 msavg l<strong>at</strong>encyNOT SO BAD SPOT
• By using a CDN we serve our users quicklyfrom 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
Next steps...
Live Bettingd<strong>at</strong>a distribution• Bet while the game is on“Who gets the next corner”, “who scores the next goal” etc• 10000:s of real-time clients need priceupd<strong>at</strong>es almost every second• 20 concurrent games• 10+ offers within one game• Product growth 60-80% per year
BettingEngine
Fan-outServerFan-outServerBettingEngine
KaazingRabbitMQKaazingRabbitMQRabbitMQBettingEngine• End-to-end messaging• RabbitMQ• Kaazing Enterprise G<strong>at</strong>eway• Google Protocol Buffers
RabbitMQ• Free Open Source and Open Standardsprotocol (AMQP)• Highly available, highly scalable (Erlang/OTP)• Excellent & friendly support available
Kaazing• Open Source and Open Standards protocol(HTML5 WebSockets)• Supported AMQP clients for Flex, browers• Connection offloading• Gre<strong>at</strong> <strong>at</strong> overcoming last mile hurdles(firewalls, proxies, browsers)• Excellent & friendly support available
Protocol Buffers• Flexible, efficient, autom<strong>at</strong>ed mechanism forserializing (binary)• Schema support (.proto files)• Language neutral (we use Java to Actionscript)• Invented and used by Google• Open Sourced in July 2008
Java/SpringBettingEngineRabbitMQ RabbitMQ KaazingFan-outnodeAS3Live BettingClientProtobufs/AMQP
Let’s get back to theCandy store...
D<strong>at</strong>acenter• Ok, the candy delivery problem is solved!• However, we cannot serve the customerschocol<strong>at</strong>e and bubble gum quickly enough• Queues are building up due to ourbottlenecks
The chocol<strong>at</strong>e bar is acacheable read
The bubble gum is anon-cacheable read ora write
The candy store checkoutis an app server
The bubble gum machineis a d<strong>at</strong>abase system
Example #1More hardware!(and sw licenses)
Kids are invading ourstore...
Food for thoughtpaying per core is paying for peaks......is not acceptable?
You cannot buy aproduct to solve thisproblem
Need to rearchitecture!
Example #2Near-cache
Terracotta• Network Attached Memory• Extends the Java threading model acrossJVM:s• In-memory speed access to d<strong>at</strong>a• Fully coherent, with stored to diskguarantees• Writes are sent as deltas across nodes
Keep d<strong>at</strong>a stored/cachedwhere it’s needed for processingJVMHeap“L1”BettingEngineBettingEngine...BettingEngineSoREventRepositoryBet OfferRepositoryTerracotta L2Live BetsEventuallyconsistentReporting/Legacywrite-behindOracle (MySQL)
Keep d<strong>at</strong>a stored/cachedwhere it’s needed for processingJVMHeap“L1”BettingEngineBettingEngine...BettingEngineupd<strong>at</strong>eSoREventRepositoryBet OfferRepositoryTerracotta L2Live Betswrite-behindReporting/LegacyOracle (MySQL)
Terracotta• L2 server can become bottleneck• Shard (free) or stripe ($$$)
Example #3Offload reads tosepar<strong>at</strong>e systems
BettingEngineBettingEngine...BettingEngineHistoryServer...HistoryServerEventRepositoryBet OfferRepositoryTerracotta L2Live BetsR R RBet HistoryOracle (MySQL)SettleBetMySQLBackoffice
Example #4Affinity +multi master replic<strong>at</strong>ion
cus-client.jarcus-client.jaruser1 user2 user3user4CustomerSystemCustomerSystemCustomerSystemCustomerSystemLDAPLDAPLDAPLDAPd<strong>at</strong>a center 1d<strong>at</strong>a center 2
Example #5Partition the d<strong>at</strong>a toscale writes
C C C• Need to get settlementsdone quickly• More than 10000 writes / sHistoryServer...HistoryServer•Scale out by using multipleMySQL instancesLive BetsBet HistoryroutingS1 S2 S3MySQL
Combining the pieces
BrowserBetting ClientFlash BettingClientHTMLGeo-distributedFan-out PushServers (Kaazing)History APISettled bets100% readBetting APILive d<strong>at</strong>acommandsprice upd<strong>at</strong>esand repliesBettingHistoryshardedwith localMySQLwrite-behindon settlementBettingEngineBettingEngineBettingEngineShared memory for events, betoffers and customer bets(Terracotta)payoutsAMQPBroker(RabbitMQ)write-behindAccountServersD<strong>at</strong>abase(MySQL)
Recap:Two main challenges• L<strong>at</strong>ency - d<strong>at</strong>a too far away from where it’sneeded• Bottlenecks - resource contention
Recipes used <strong>at</strong> <strong>Unibet</strong>inform<strong>at</strong>ion delivery• Optimize your web apps!• Get rid of st<strong>at</strong>ic object traffic• Move web d<strong>at</strong>a closer to customers (CDN)• Last-mile fan-out messaging
Recipes used <strong>at</strong> <strong>Unibet</strong>in the d<strong>at</strong>a center• Move d<strong>at</strong>a to business logic• Read-only farms• Multi-master replic<strong>at</strong>ion for read-mostlyd<strong>at</strong>a• Sharding to scale writes
Open Source Software and Services isused by <strong>Unibet</strong> extensively in missioncritical applic<strong>at</strong>ions because...
...we are convinced it’s better andmore cost effective!
Thanks!(we’re hiring)@stnorstefan.norberg@unibet.comstnor.wordpress.comwww.linkedin.com/in/stnor