AT	
  SCALE	
  WITH	
  STYLE
                      Erlang	
  <3	
  <3	
  <3	
  Ruby




Mar$n	
  Rehfeld,	
  @klickmich
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
At Scale With Style
Typical	
  game	
  architecture

         Client         HTTP      Backend
                         API
Typical	
  game	
  architecture

                                  Backend




     State	
  Changes
       ValidaHon
      Persistence
The	
  scale	
  is	
  interesHng


              14	
  billion	
  requests	
  /	
  month



          >100,000	
  DB	
  operaHons	
  /	
  second



             >50,000	
  DB	
  updates	
  /	
  second
Wooga’s	
  approach	
  to	
  development

Small	
  independent	
  teams	
  for	
  each	
  game

Team	
  gets	
  to	
  choose	
  tools	
  and	
  technologies
  Same	
  team	
  also	
  does	
  ops	
  a,er	
  going	
  live

Culture	
  of	
  sharing
  Look	
  around	
  what	
  is	
  there,	
  pick/adapt	
  exis;ng	
  
   solu;ons,	
  but	
  take	
  ownership	
  for	
  what	
  you	
  
   include
ExisHng	
  backends	
  –	
  Technology	
  landscape
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
Most	
  games	
  use	
  stateless	
  applicaHon	
  servers

         Server                          Database
And	
  then	
  there’s	
  sharding

                                  lb




        app   app   app   app     app    app    app   app   app




                          My            My
                          SQL           SQL


                          slave         slave
More	
  app	
  servers,	
  more	
  sharding

                                              lb




            app         app     app   app     app   app     app      app         app


            app     app         app   app     app   app     app      app         app




    My            My          My      My            My       My            My          My
    SQL           SQL         SQL     SQL           SQL      SQL           SQL         SQL


    slave     slave           slave   slave         slave    slave     slave           slave
Wait,	
  seriously?!

                                               lb         lb


app     app      app     app     app   app          app        app     app      app   app     app   app


app     app      app     app     app   app          app        app     app      app   app     app   app


app     app      app     app     app   app          app        app     app      app   app     app   app


My       My            My      My      My
                                                               redis    redis     redis     redis   redis
SQL      SQL           SQL     SQL     SQL


slave    slave     slave       slave   slave                   slave    slave     slave     slave   slave
Find	
  the	
  flaw

 “Stateless	
  applicaHon	
  servers	
  
      guarantee	
  one	
  thing:
       The	
  data	
  is	
  never
      where	
  you	
  need	
  it!”
          Paolo	
  Negri,	
  Developer	
  @	
  Wooga
Strong	
  session	
  pa`ern


   User	
  starts	
  playing

     many	
  transformaHons
     of	
  the	
  same	
  set	
  of	
  data


   User	
  stops	
  playing
Stateful	
  servers	
  and	
  DBs

          Server                              Database




                     One	
  Game	
  Session
Stateful	
  game	
  server

One	
  process	
  per	
  acHve	
  user	
  gaming	
  session

    ...	
  holds	
  the	
  current	
  state	
  and	
  is	
  the	
  only	
  one	
  that	
  can	
  
         modify	
  it	
  (strong	
  encapsulaHon)

    ...	
  handles	
  all	
  API	
  calls	
  for	
  the	
  given	
  user	
  one	
  a,er	
  the	
  other	
  
         (concurrency	
  control	
  through	
  actor	
  model)

    ...	
  loads	
  the	
  game	
  state	
  from	
  storage	
  and	
  writes	
  it	
  back	
  
         periodically	
  and	
  on	
  process	
  termina;on
         (;meout	
  =	
  user	
  stopped	
  playing)
The	
  DB	
  is	
  no	
  longer	
  the	
  bo`leneck


                     Stateless                     Stateful

  30.000
  22.500
  15.000
                                                   700
   7.500
        0
                      DB	
  operations	
  /	
  second
Magic	
  Land	
  uses	
  Erlang

Details:
Awesome	
  presentaHon	
  on
the	
  Magic	
  Land	
  game	
  server
by	
  @knuHn	
  &	
  @hungryblank


h`p://www.slideshare.net/wooga/from-­‐0-­‐to-­‐1000000-­‐daily-­‐users-­‐with-­‐erlang
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
At Scale With Style
Erlang	
  &	
  Ruby

Erlang	
  is	
  great
   Concurrent,	
  robust
   Great	
  for	
  opera;on

Ruby	
  is	
  great
  Concise,	
  expressive,	
  flexible
  Great	
  for	
  development
At Scale With Style
Bringing	
  two	
  worlds	
  together




                 Server                 Worker

       session
                          sender        Worker

       session
                                        Worker

         ...
                                        Worker
                          receiver
       session
                                        Worker
Do	
  you	
  know	
  Mongrel2?

                          Web	
  Server	
  that	
  hooks
                          up	
  applicaHons	
  via


➡ We	
  chose	
  the	
  same	
  queue	
  setup	
  &	
  
  message	
  format
                                            Server              Worker

                                  session

                                                     sender
                                                                Worker

                                  session
                                                                Worker

                                    ...
                                                                Worker
                                                     receiver


                                  session
                                                                Worker
At Scale With Style
ConnecHng	
  the	
  dots

Mongrel2	
  h`p://mongrel2.org/	
  protocol	
  &	
  ZeroMQ	
  setup
Erlang:	
  h`ps://github.com/hungryblank/emongrel2
Ruby
    rack-­‐mongrel2	
  fork	
  hKps://github.com/khiltd/khi-­‐rack-­‐mongrel2
    rack	
  protocol	
  hKp://rack.rubyforge.org
    Sinatra	
  hKp://www.sinatrarb.com/


➡      essenHally	
  we	
  are	
  speaking	
  HTTP	
  over	
  ZeroMQ
       and	
  can	
  hook	
  up	
  any	
  Rack-­‐based	
  Ruby	
  web	
  
       framework
Example	
  controller	
  in	
  Ruby
  app.game_action '/:actor/fruit_tree/self/shake',
                  :observable => true,
                  :affects => [:fruit_trees, :user],
                  :params => [:x, :y] do

    x, y = params[:x], params[:y]
    fruit_trees[x, y].shake

 end




DSL-­‐like	
  definiHon	
  of	
  game	
  acHon
Skinny	
  as	
  controllers	
  should	
  be
Example	
  model	
  in	
  Ruby
  class FruitTree < Tree

    property :last_shake_time,         :type => Integer, :default => 0
    property :collectable_fruit_count, :type => Integer, :default => 0

    def shake
      raise G8::Error::Validation, "no fruit!" unless carries_fruit?

      session.user.xp += 1
      session.user.energy -= 1
      self.last_shake_time = game_time
      self.collectable_fruit_count = config.fruit_count
    end

  end


Easily	
  unit	
  testable
Minimal	
  amount	
  of	
  code
Game	
  state

Game	
  state	
  is	
  split	
  in	
  mulHple	
  parts
  user,	
  map,	
  fruit_trees	
  etc.

Erlang	
  does	
  not	
  care	
  about	
  content
   Serialized	
  Ruby	
  objects

Erlang	
  does	
  know	
  mapping	
  of	
  state	
  parts	
  to	
  URLs
Looking	
  back	
  at	
  the	
  game	
  acHon
app.game_action '/:actor/fruit_tree/self/shake',
                :observable => true,
                :affects => [:fruit_trees, :user],
                :params => [:x, :y] do

  x, y = params[:x], params[:y]
  fruit_trees[x, y].shake
end



Mapping	
  of	
  state	
  parts	
  to	
  game	
  acHons
  Worker	
  knows	
  mapping
  Worker	
  pushes	
  mapping	
  to	
  Erlang	
  on	
  startup
  Erlang	
  can	
  query	
  mapping	
  if	
  needed
NICE!
        http://www.flickr.com/photos/aigle_dore/
At	
  Scale	
  With	
  Style

 How	
  we	
  roll

 Server	
  architectures

 How	
  to	
  innovate

 Mind	
  the	
  limits
Performance	
  impact	
  for	
  large	
  payloads
                                200	
  kB	
  payload
                     6000

                     5000
Requests	
  /	
  s




                     4000
                                                            Pure
                     3000                                  Erlang
                     2000
                                                            Ruby
                     1000                                   ZMQ
                                                           400	
  rps
                       0
                            1     #	
  of	
  workers   8
NOT	
  CPU	
  bound




25%



         Fixed	
  bandwith	
  limit	
  @	
  300	
  MB/s
This	
  has	
  happened	
  before
2,000,000"




1,500,000"




1,000,000"




 500,000"




        0"
        Apr*10"   Jul*10"   Oct*10"   Jan*11"   Apr*11"   Jul*11"   Oct*11"
At Scale With Style
Example	
  controller	
  in	
  Erlang

  shake(Args, State) ->
      Coords      = g8_map:coords(Args),
      Map         = g8_game:get_map(State),
      Tree        = g8_map:find(Coords, Map),

      NewTree     = g8_fruit_tree:shake(Tree),
      UserEffects = [incr_xp, decr_energy],
      NewMap      = g8_map:place(Coords, NewTree, Map),

      [observable,
       {state, g8_game:set_map(NewMap,
                 g8_user:apply(UserEffects, State))}].
Example	
  model	
  in	
  Erlang

  shake(Tree) ->
      validate_carries_fruit(Tree),

      FruitCount = g8_fruit_tree_config:fruit_count(Tree),
      Tree#fruit_tree{last_shake_time = g8_game:gametime(),
                      collectable_fruit_count = FruitCount}.
✓ Y ES
QuesHons?

   MarHn	
  Rehfeld
    @klickmich

slideshare.net/wooga
   wooga.com/jobs

More Related Content

PDF
Combining the strength of erlang and Ruby
ODP
Open Source Compiler Construction for the JVM
PPTX
Java 7 Whats New(), Whats Next() from Oredev
PDF
TorqueBox for Rubyists
PDF
TorqueBox at DC:JBUG - November 2011
ODP
Pfm technical-inside
PDF
DataMapper on Infinispan
KEY
Devignition 2011
Combining the strength of erlang and Ruby
Open Source Compiler Construction for the JVM
Java 7 Whats New(), Whats Next() from Oredev
TorqueBox for Rubyists
TorqueBox at DC:JBUG - November 2011
Pfm technical-inside
DataMapper on Infinispan
Devignition 2011

What's hot (18)

PDF
Complex Made Simple: Sleep Better with TorqueBox
PDF
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
PDF
A Tale of a Server Architecture (Frozen Rails 2012)
KEY
TorqueBox - Ruby Hoedown 2011
PDF
Rocket Fuelled Cucumbers
PDF
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
KEY
Jruby synergy-of-ruby-and-java
PPT
Java, Ruby & Rails
ZIP
Above the clouds: introducing Akka
PPTX
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
PDF
A tour of (advanced) Akka features in 40 minutes
PDF
The Enterprise Strikes Back
PDF
Modern Objective-C @ Pragma Night
KEY
When Two Worlds Collide: Java and Ruby in the Enterprise
KEY
Message queueing
PDF
Automatic Reference Counting @ Pragma Night
PDF
When Ruby Meets Java - The Power of Torquebox
PDF
Connecting the Worlds of Java and Ruby with JRuby
Complex Made Simple: Sleep Better with TorqueBox
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
A Tale of a Server Architecture (Frozen Rails 2012)
TorqueBox - Ruby Hoedown 2011
Rocket Fuelled Cucumbers
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
Jruby synergy-of-ruby-and-java
Java, Ruby & Rails
Above the clouds: introducing Akka
Running Ruby on Solaris (RubyKaigi 2015, 12/Dec/2015)
A tour of (advanced) Akka features in 40 minutes
The Enterprise Strikes Back
Modern Objective-C @ Pragma Night
When Two Worlds Collide: Java and Ruby in the Enterprise
Message queueing
Automatic Reference Counting @ Pragma Night
When Ruby Meets Java - The Power of Torquebox
Connecting the Worlds of Java and Ruby with JRuby
Ad

Similar to At Scale With Style (20)

PDF
Combining the Strengths or Erlang and Ruby
PDF
Games for the Masses (Jax)
KEY
Polyglot parallelism
PDF
O que tem de novo no Ruby 2.0?
PDF
Erlang and the Cloud: A Fractal Approach to Throughput
PDF
Erlang as a Cloud Citizen
PDF
Erlang as a cloud citizen, a fractal approach to throughput
KEY
Redis, Resque & Friends
PDF
Games for the Masses (QCon London 2012)
PDF
SCALE 10x Build a Cloud Day
PDF
Agile Seaside
PDF
Seaside — Agile Software Development
PPT
Large-scale projects development (scaling LAMP)
PDF
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
PDF
BruCON 2010 Lightning Talks - DIY Grid Computing
PDF
Server Tips
PDF
Lindsay distributed geventzmq
PDF
Why Erlang? - Bar Camp Atlanta 2008
PPTX
Usenix lisa 2011
PDF
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Combining the Strengths or Erlang and Ruby
Games for the Masses (Jax)
Polyglot parallelism
O que tem de novo no Ruby 2.0?
Erlang and the Cloud: A Fractal Approach to Throughput
Erlang as a Cloud Citizen
Erlang as a cloud citizen, a fractal approach to throughput
Redis, Resque & Friends
Games for the Masses (QCon London 2012)
SCALE 10x Build a Cloud Day
Agile Seaside
Seaside — Agile Software Development
Large-scale projects development (scaling LAMP)
Architecture Evolution at Wooga (AWS Cloud Computing for Developers,)
BruCON 2010 Lightning Talks - DIY Grid Computing
Server Tips
Lindsay distributed geventzmq
Why Erlang? - Bar Camp Atlanta 2008
Usenix lisa 2011
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Ad

Recently uploaded (20)

PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
DOCX
search engine optimization ppt fir known well about this
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
Five Habits of High-Impact Board Members
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PPTX
Configure Apache Mutual Authentication
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
A proposed approach for plagiarism detection in Myanmar Unicode text
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
NewMind AI Weekly Chronicles – August ’25 Week III
search engine optimization ppt fir known well about this
UiPath Agentic Automation session 1: RPA to Agents
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Flame analysis and combustion estimation using large language and vision assi...
Five Habits of High-Impact Board Members
Getting started with AI Agents and Multi-Agent Systems
The influence of sentiment analysis in enhancing early warning system model f...
Configure Apache Mutual Authentication
Taming the Chaos: How to Turn Unstructured Data into Decisions
Consumable AI The What, Why & How for Small Teams.pdf
Convolutional neural network based encoder-decoder for efficient real-time ob...
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Module 1.ppt Iot fundamentals and Architecture
Final SEM Unit 1 for mit wpu at pune .pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
sustainability-14-14877-v2.pddhzftheheeeee
A contest of sentiment analysis: k-nearest neighbor versus neural network

At Scale With Style

  • 1. AT  SCALE  WITH  STYLE Erlang  <3  <3  <3  Ruby Mar$n  Rehfeld,  @klickmich
  • 2. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 4. Typical  game  architecture Client HTTP Backend API
  • 5. Typical  game  architecture Backend State  Changes ValidaHon Persistence
  • 6. The  scale  is  interesHng 14  billion  requests  /  month >100,000  DB  operaHons  /  second >50,000  DB  updates  /  second
  • 7. Wooga’s  approach  to  development Small  independent  teams  for  each  game Team  gets  to  choose  tools  and  technologies Same  team  also  does  ops  a,er  going  live Culture  of  sharing Look  around  what  is  there,  pick/adapt  exis;ng   solu;ons,  but  take  ownership  for  what  you   include
  • 8. ExisHng  backends  –  Technology  landscape
  • 9. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 10. Most  games  use  stateless  applicaHon  servers Server Database
  • 11. And  then  there’s  sharding lb app app app app app app app app app My My SQL SQL slave slave
  • 12. More  app  servers,  more  sharding lb app app app app app app app app app app app app app app app app app app My My My My My My My My SQL SQL SQL SQL SQL SQL SQL SQL slave slave slave slave slave slave slave slave
  • 13. Wait,  seriously?! lb lb app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app app My My My My My redis redis redis redis redis SQL SQL SQL SQL SQL slave slave slave slave slave slave slave slave slave slave
  • 14. Find  the  flaw “Stateless  applicaHon  servers   guarantee  one  thing: The  data  is  never where  you  need  it!” Paolo  Negri,  Developer  @  Wooga
  • 15. Strong  session  pa`ern User  starts  playing many  transformaHons of  the  same  set  of  data User  stops  playing
  • 16. Stateful  servers  and  DBs Server Database One  Game  Session
  • 17. Stateful  game  server One  process  per  acHve  user  gaming  session ...  holds  the  current  state  and  is  the  only  one  that  can   modify  it  (strong  encapsulaHon) ...  handles  all  API  calls  for  the  given  user  one  a,er  the  other   (concurrency  control  through  actor  model) ...  loads  the  game  state  from  storage  and  writes  it  back   periodically  and  on  process  termina;on (;meout  =  user  stopped  playing)
  • 18. The  DB  is  no  longer  the  bo`leneck Stateless Stateful 30.000 22.500 15.000 700 7.500 0 DB  operations  /  second
  • 19. Magic  Land  uses  Erlang Details: Awesome  presentaHon  on the  Magic  Land  game  server by  @knuHn  &  @hungryblank h`p://www.slideshare.net/wooga/from-­‐0-­‐to-­‐1000000-­‐daily-­‐users-­‐with-­‐erlang
  • 20. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 22. Erlang  &  Ruby Erlang  is  great Concurrent,  robust Great  for  opera;on Ruby  is  great Concise,  expressive,  flexible Great  for  development
  • 24. Bringing  two  worlds  together Server Worker session sender Worker session Worker ... Worker receiver session Worker
  • 25. Do  you  know  Mongrel2? Web  Server  that  hooks up  applicaHons  via ➡ We  chose  the  same  queue  setup  &   message  format Server Worker session sender Worker session Worker ... Worker receiver session Worker
  • 27. ConnecHng  the  dots Mongrel2  h`p://mongrel2.org/  protocol  &  ZeroMQ  setup Erlang:  h`ps://github.com/hungryblank/emongrel2 Ruby rack-­‐mongrel2  fork  hKps://github.com/khiltd/khi-­‐rack-­‐mongrel2 rack  protocol  hKp://rack.rubyforge.org Sinatra  hKp://www.sinatrarb.com/ ➡ essenHally  we  are  speaking  HTTP  over  ZeroMQ and  can  hook  up  any  Rack-­‐based  Ruby  web   framework
  • 28. Example  controller  in  Ruby app.game_action '/:actor/fruit_tree/self/shake', :observable => true, :affects => [:fruit_trees, :user], :params => [:x, :y] do x, y = params[:x], params[:y] fruit_trees[x, y].shake end DSL-­‐like  definiHon  of  game  acHon Skinny  as  controllers  should  be
  • 29. Example  model  in  Ruby class FruitTree < Tree property :last_shake_time, :type => Integer, :default => 0 property :collectable_fruit_count, :type => Integer, :default => 0 def shake raise G8::Error::Validation, "no fruit!" unless carries_fruit? session.user.xp += 1 session.user.energy -= 1 self.last_shake_time = game_time self.collectable_fruit_count = config.fruit_count end end Easily  unit  testable Minimal  amount  of  code
  • 30. Game  state Game  state  is  split  in  mulHple  parts user,  map,  fruit_trees  etc. Erlang  does  not  care  about  content Serialized  Ruby  objects Erlang  does  know  mapping  of  state  parts  to  URLs
  • 31. Looking  back  at  the  game  acHon app.game_action '/:actor/fruit_tree/self/shake', :observable => true, :affects => [:fruit_trees, :user], :params => [:x, :y] do x, y = params[:x], params[:y] fruit_trees[x, y].shake end Mapping  of  state  parts  to  game  acHons Worker  knows  mapping Worker  pushes  mapping  to  Erlang  on  startup Erlang  can  query  mapping  if  needed
  • 32. NICE! http://www.flickr.com/photos/aigle_dore/
  • 33. At  Scale  With  Style How  we  roll Server  architectures How  to  innovate Mind  the  limits
  • 34. Performance  impact  for  large  payloads 200  kB  payload 6000 5000 Requests  /  s 4000 Pure 3000 Erlang 2000 Ruby 1000 ZMQ 400  rps 0 1 #  of  workers 8
  • 35. NOT  CPU  bound 25% Fixed  bandwith  limit  @  300  MB/s
  • 36. This  has  happened  before 2,000,000" 1,500,000" 1,000,000" 500,000" 0" Apr*10" Jul*10" Oct*10" Jan*11" Apr*11" Jul*11" Oct*11"
  • 38. Example  controller  in  Erlang shake(Args, State) -> Coords = g8_map:coords(Args), Map = g8_game:get_map(State), Tree = g8_map:find(Coords, Map), NewTree = g8_fruit_tree:shake(Tree), UserEffects = [incr_xp, decr_energy], NewMap = g8_map:place(Coords, NewTree, Map), [observable, {state, g8_game:set_map(NewMap, g8_user:apply(UserEffects, State))}].
  • 39. Example  model  in  Erlang shake(Tree) -> validate_carries_fruit(Tree), FruitCount = g8_fruit_tree_config:fruit_count(Tree), Tree#fruit_tree{last_shake_time = g8_game:gametime(), collectable_fruit_count = FruitCount}.
  • 41. QuesHons? MarHn  Rehfeld @klickmich slideshare.net/wooga wooga.com/jobs