Your SlideShare is downloading. ×
0
Chiyoung Seo, Couchbase Inc.<br />Matt Ingenthron, Couchbase Inc.<br />Using Couchbase For Social game scaling and speed <...
Introduction<br />What is Couchbase Server?<br />Simple, Fast, Elastic<br />Technology Overview (Architecture, data flow, ...
Membase and CouchOne have merged to form Couchbase Inc. (headquartered in Silicon Valley)<br />Team<br />Brings together t...
Modern Interactive Web Application Architecture<br />Application Scales Out<br />Just add more commodity web servers<br />...
Couchbase Server is a distributed database<br />CouchbaseWeb Console<br />Application user<br />Web  application  server<b...
Couchbase data layer scales like application logic tierData layer now scales with linear cost and constant performance.<br...
Couchbase Server is Simple, Fast, Elastic<br />Five minutes or less to a working cluster<br />Downloads for Windows, Linux...
Couchbase Server is Simple, Fast, Elastic<br />Predictable<br />“Never keep an application waiting”<br />Quasi-determinist...
Couchbase Server is Simple, Fast, Elastic<br />Zero-downtime elasticity<br />Spread I/O and data across commodity servers ...
Proven at Small, and Extra Large Scale<br />Leading cloud service (PAAS) provider<br />Over 150,000 hosted applications<br...
Over 230 million monthly users
Couchbase Server is the primary database behind key Zynga properties</li></li></ul><li>Customers and Partners<br />Custome...
11211<br />11210<br />memcapable 1.0<br />memcapable 2.0<br />moxi<br />memcached<br />protocol listener/sender<br />REST ...
11211<br />11210<br />memcapable 1.0<br />memcapable 2.0<br />moxi<br />memcached<br />protocol listener/sender<br />REST ...
Couchbase “write” Data Flow – application view<br />User action results in the need to change the VALUE of KEY<br />1<br /...
Couchbase Data Flow – under the hood<br />SET request arrives at KEY’s master server<br />SET acknowledgement returned to ...
Elasticity - Rebalancing<br />Node 1<br />Node 2<br />Node 3<br />Before<br /><ul><li>Adding Node 3
Node 3 is in pending state
Clients talk to Node 1,2 only</li></ul>vBucket 1<br />vBucket 7<br />vBucket 2<br />vBucket 8<br />vBucket 3<br />vBucket ...
Migrate vBucketsto the new server
Finalize migration</li></ul>vBucket 2<br />vBucket 8<br />vBucket 3<br />vBucket 9<br />Rebalancing<br />vBucket 4<br />vB...
Clients are reconfigured to talk to Node 3</li></ul>vBucket 5<br />vBucket 1<br />vBucket 7<br />vBucket 6<br />vBucket 2<...
Data buckets are secure Couchbase “slices”<br />Application user<br />Web application server<br />Bucket 1<br />Bucket 2<b...
Support large-scale analytics on application data by streaming  data from Couchbase to Hadoop<br />Real-time integration u...
Introduction<br />What is Couchbase Server?<br />Simple, Fast, Elastic<br />Technology Overview (Architecture, data flow, ...
Common steps on scaling up database:<br />Tune queries (indexing, explain query)<br />Denormalization<br />Cache data (APC...
Tribal Crossing: Challenges<br />Write-heavy requests<br />Caching does not help<br />MySQL / InnoDB limitation (Percona)<...
MySQL with master-to-master replication and sharding<br />Complex to setup, high administration cost<br />Requires applica...
SPEED, SPEED, SPEED<br />Immediate consistency<br />Interface is dead simple to use<br />We are already using Memcache<br ...
But, there are some different challenges in using Couchbase (currently 1.7) to handle the game data:<br />No easy way to q...
Tribal Crossing: Deploying Couchbase in EC2<br />Web Server<br />Basic production environment setup<br />Dev/Stage environ...
Tribal Crossing: Deploying Couchbasein EC2<br />Web Server<br />Amazon Linux AMI, 64-bit, EBS backed instance<br />Setup s...
Tribal Crossing: Deploying Couchbase in EC2<br />Web Server<br />Moxi figures out which node in the cluster holds data for...
Tribal Crossing: Representing Game Data in Couchbase<br />Use case - simple farming game:<br />A player can have a variety...
Representing Objects<br />Simply treat an object as an associative array<br />Determine the key for an object using the cl...
Tribal Crossing: Representing Game Data in Couchbase<br />Player Object<br />Key: 'Player1'<br />Array<br />(<br />  [Id] ...
No need to “ALTER TABLE”<br />Add new “fields” all objects at any time<br />Specify default value for missing fields<br />...
Tribal Crossing: Accessing Game Data in Couchbase<br />Get all plants belong to a given player<br />Request:  GET  /player...
Give a player a new plant<br />// Create the new plant<br />$new_plant = array (<br />  'id'   => 100,<br />  'name' => 'M...
Concurrency issue can occur when multiple requests are working with the same piece of data.<br />Solution:<br />CAS (check...
Record object relationships both ways<br />Example:  Plots and Plants<br />Plot object stores id of the plant that it host...
First migrated large or slow performing tables and frequently updated fields from MySQL to Couchbase<br />Web Server<br />...
Tribal Crossing: Deployment <br />
Tribal Crossing: Deployment<br />
Upcoming SlideShare
Loading in...5
×

Couchbase Seoul Data Engineering Conference (SDEC) 2011

2,767

Published on

Published in: Technology

Transcript of "Couchbase Seoul Data Engineering Conference (SDEC) 2011"

  1. 1.
  2. 2. Chiyoung Seo, Couchbase Inc.<br />Matt Ingenthron, Couchbase Inc.<br />Using Couchbase For Social game scaling and speed <br />
  3. 3. Introduction<br />What is Couchbase Server?<br />Simple, Fast, Elastic<br />Technology Overview (Architecture, data flow, rebalancing)<br />Tribal Crossing Inc: Animal Party<br />Challenges before Couchbase<br />Original Architecture<br />Why Couchbase?<br />Simplicity<br />Performance<br />Flexibility<br />Deploying Couchbase<br />New Architecture<br />EC2<br />Data Model<br />Accessing data in Couchbase<br />Product Roadmap<br />Q&A<br />Agenda<br />
  4. 4. Membase and CouchOne have merged to form Couchbase Inc. (headquartered in Silicon Valley)<br />Team<br />Brings together the creators and core contributors of Memcached, Membase and CouchDB technologies<br />Doubles technical team size, accelerates roadmaps by over a year<br />Products<br />Couchbase Server (Formerly Membase)<br />Couchbase Single Server<br />Mobile Couchbase (iPhone and Android)<br />Technology<br />Most mature, reliable and widely deployed NoSQL technologies<br />Fully featured, open source document datastore<br />First complete, end-to-end NoSQL database product<br />Couchbase Inc.<br />
  5. 5. Modern Interactive Web Application Architecture<br />Application Scales Out<br />Just add more commodity web servers<br />www.facebook.com/animalparty<br />Load Balancer<br />WebServers<br />Database Scales Up<br />Get a bigger, more complex server<br />Relational <br />Database<br />- Expensive and disruptive sharding<br />- Doesn’t perform at Web Scale<br />
  6. 6. Couchbase Server is a distributed database<br />CouchbaseWeb Console<br />Application user<br />Web application server<br />Couchbase Servers<br />
  7. 7. Couchbase data layer scales like application logic tierData layer now scales with linear cost and constant performance.<br />Application Scales Out<br />Just add more commodity web servers<br />www.facebook.com/animalparty<br />Load Balancer<br />Web Servers<br />Couchbase Servers<br />Database Scales Out<br />Just add more commodity data servers<br />Horizontally scalable, schema-less, auto-sharding, high-performance at Web Scale<br />Scaling out flattens the cost and performance curves.<br />
  8. 8. Couchbase Server is Simple, Fast, Elastic<br />Five minutes or less to a working cluster<br />Downloads for Windows, Linux and OSX<br />Start with a single node<br />One button press joins nodes to a cluster<br />Easy to develop against<br />Just SET and GET – no schema required<br />Drop it in. 10,000+ existing applications already “speak Couchbase” (via memcached)<br />Practically every language and application framework is supported, out of the box<br />Easy to manage<br />One-click failover and cluster rebalancing<br />Graphical and programmatic interfaces<br />Configurable alerting<br />
  9. 9. Couchbase Server is Simple, Fast, Elastic<br />Predictable<br />“Never keep an application waiting”<br />Quasi-deterministic latency and throughput<br />Low latency<br />Built-in Memcached technology<br />Auto-migration of hot data to lowest latency storage technology (RAM, SSD, Disk)<br />Selectable write behavior – asynchronous, synchronous (on replication, persistence)<br />High throughput<br />Multi-threaded<br />Low lock contention<br />Asynchronous wherever possible<br />Automatic write de-duplication<br />
  10. 10. Couchbase Server is Simple, Fast, Elastic<br />Zero-downtime elasticity<br />Spread I/O and data across commodity servers (or VMs) <br />Consistent performance with linear cost<br />Dynamic rebalancing of a live cluster<br />All nodes are created equal<br />No special case nodes<br />Clone to grow<br />Extensible<br />Change feeds<br />Real-time map-reduce<br />RESTful interface for management<br />CouchbaseWeb Console<br />
  11. 11. Proven at Small, and Extra Large Scale<br />Leading cloud service (PAAS) provider<br />Over 150,000 hosted applications<br />Couchbase Server serving over 6,200 Heroku customers<br /><ul><li>Social game leader – FarmVille, Mafia Wars, Empires and Allies, Café World, FishVille
  12. 12. Over 230 million monthly users
  13. 13. Couchbase Server is the primary database behind key Zynga properties</li></li></ul><li>Customers and Partners<br />Customers (partial listing)<br />Partners<br />
  14. 14. 11211<br />11210<br />memcapable 1.0<br />memcapable 2.0<br />moxi<br />memcached<br />protocol listener/sender<br />REST management API/Web UI<br />vBucket state and replication manager<br />Rebalance orchestrator<br />Node health monitor<br />Heartbeat<br />Process monitor<br />Global singleton supervisor<br />Configuration manager<br />Data Manager<br />Cluster Manager<br />engine interface<br />Couchbase Storage Engine<br />http<br />on each node<br />one per cluster<br />Erlang/OTP<br />HTTP<br />distributed erlang<br />erlang port mapper<br />21100 – 21199<br />4369<br />8091<br />Couchbase Server Architecture<br />
  15. 15. 11211<br />11210<br />memcapable 1.0<br />memcapable 2.0<br />moxi<br />memcached<br />protocol listener/sender<br />REST management API/Web UI<br />vBucket state and replication manager<br />Rebalance orchestrator<br />Node health monitor<br />Heartbeat<br />Process monitor<br />Global singleton supervisor<br />Configuration manager<br />engine interface<br />Couchbase Storage Engine<br />http<br />on each node<br />one per cluster<br />Erlang/OTP<br />HTTP<br />distributed erlang<br />erlang port mapper<br />21100 – 21199<br />4369<br />8091<br />Couchbase Server Architecture<br />
  16. 16. Couchbase “write” Data Flow – application view<br />User action results in the need to change the VALUE of KEY<br />1<br />Application updates key’s VALUE, performs SET operation <br />2<br />4<br />Couchbase client hashes KEY, identifies KEY’s master server<br />3<br />SET request sent over network to master server<br />5<br />Couchbase replicates KEY-VALUE pair, caches it in memory and stores it to disk<br />
  17. 17. Couchbase Data Flow – under the hood<br />SET request arrives at KEY’s master server<br />SET acknowledgement returned to application<br />1<br />3<br />2<br />2<br />Listener-Sender<br />RAM*<br />2<br />SSD<br />SSD<br />SSD<br />Couchbase storage engine<br />4<br />Disk<br />Disk<br />Disk<br />Master server for KEY<br />Replica Server 2 for KEY<br />Replica Server 1 for KEY<br />
  18. 18. Elasticity - Rebalancing<br />Node 1<br />Node 2<br />Node 3<br />Before<br /><ul><li>Adding Node 3
  19. 19. Node 3 is in pending state
  20. 20. Clients talk to Node 1,2 only</li></ul>vBucket 1<br />vBucket 7<br />vBucket 2<br />vBucket 8<br />vBucket 3<br />vBucket 9<br />Pending state<br />vBucket 4<br />vBucket 10<br />vBucket 5<br />vBucket 11<br />vBucket 6<br />vBucket 12<br />vBucket 1<br />vBucket 7<br />During<br /><ul><li>Rebalancing orchestrator recalculates the vBucket map (including replicas)
  21. 21. Migrate vBucketsto the new server
  22. 22. Finalize migration</li></ul>vBucket 2<br />vBucket 8<br />vBucket 3<br />vBucket 9<br />Rebalancing<br />vBucket 4<br />vBucket 10<br />vBucket 5<br />vBucket 11<br />vBucket 6<br />vBucket 12<br />vBucket migrator<br />vBucket migrator<br />Client<br />After<br /><ul><li>Node 3 is balanced
  23. 23. Clients are reconfigured to talk to Node 3</li></ul>vBucket 5<br />vBucket 1<br />vBucket 7<br />vBucket 6<br />vBucket 2<br />vBucket 8<br />vBucket 11<br />vBucket 3<br />vBucket 9<br />vBucket 12<br />vBucket 4<br />vBucket 10<br />
  24. 24. Data buckets are secure Couchbase “slices”<br />Application user<br />Web application server<br />Bucket 1<br />Bucket 2<br />Aggregate Cluster Memory and Disk Capacity<br />Couchbase data servers<br />In the data center<br />On the administrator console<br />
  25. 25. Support large-scale analytics on application data by streaming data from Couchbase to Hadoop<br />Real-time integration using Flume<br />Batch integration using Sqoop<br />Examples<br />Various game statistics (e.g., monthly / daily / hourly rankings)<br />Analyze game patterns from users to enhance various game metrics <br />Couchbase and Hadoop Integration<br />Flume<br />memcached<br />protocol listener/sender<br />TAP<br />Sqoop<br />engine interface<br />Couchbase Storage Engine<br />
  26. 26. Introduction<br />What is Couchbase Server?<br />Simple, Fast, Elastic<br />Technology Overview (Architecture, data flow, rebalancing)<br />Tribal Crossing Inc: Animal Party<br />Challenges before Couchbase<br />Original Architecture<br />Why Couchbase?<br />Simplicity<br />Performance<br />Flexibility<br />Deploying Couchbase<br />New Architecture<br />EC2<br />Data Model<br />Accessing data in Couchbase<br />Product Roadmap<br />Q&A<br />Agenda<br />
  27. 27. Common steps on scaling up database:<br />Tune queries (indexing, explain query)<br />Denormalization<br />Cache data (APC / Memcache)<br />Tune MySQL configuration<br />Replication (read slaves)<br />Where do we go from here to prepare for the scale of a successful social game?<br />Tribal Crossing: Challenges<br />
  28. 28. Tribal Crossing: Challenges<br />Write-heavy requests<br />Caching does not help<br />MySQL / InnoDB limitation (Percona)<br />Need to scale drastically over night<br />My Polls – 100 to 1m users over a weekend<br />Small team, no dedicated sysadmin<br />Focus on what we do best – making games<br />Keeping cost down<br />
  29. 29. MySQL with master-to-master replication and sharding<br />Complex to setup, high administration cost<br />Requires application level changes<br />Cassandra<br />High write, but low read throughput<br />Live cluster reconfiguration and rebalance is quite complicated<br />Eventual consistency gives too much burden to application developers<br />MongoDB<br />High read/write, but unpredictable latency<br />Live cluster rebalance for existing nodes only<br />Eventual consistency with slave nodes<br />Tribal Crossing: “Old” Architecture and Options<br />
  30. 30. SPEED, SPEED, SPEED<br />Immediate consistency<br />Interface is dead simple to use<br />We are already using Memcache<br />Low sysadmin overhead<br />Schema-less data store<br />Used and Proven by big guys like Zynga<br />… and lastly, because Tribal CAN<br />Bigger firms with legacy code base = hard to adapt<br />Small team = ability to get on the cutting edge<br />Tribal Crossing: Why Couchbase Server?<br />
  31. 31. But, there are some different challenges in using Couchbase (currently 1.7) to handle the game data:<br />No easy way to query data<br />No transaction / rollback<br />Couchbase Server 2.0 resolves them by using CouchDB as the underlying database engine<br />Can this work for an online game?<br />Break out of the old ORM / relational paradigm!<br />We are not handling bank transactions<br />Tribal Crossing: New Challenges With Couchbase<br />
  32. 32. Tribal Crossing: Deploying Couchbase in EC2<br />Web Server<br />Basic production environment setup<br />Dev/Stage environment – feel free to install Couchbase on your web server<br />Apache<br />Client-side Moxi<br />Cluster Mgmt.<br />Requests<br />DNS Entry<br />Couchbase Cluster<br />Couchbase<br />Couchbase<br />…<br />
  33. 33. Tribal Crossing: Deploying Couchbasein EC2<br />Web Server<br />Amazon Linux AMI, 64-bit, EBS backed instance<br />Setup swap space<br />Install Couchbase’sMembase Server 1.7<br />Access web consolehttp://<hostname>:8091<br />Start the new cluster with a single node<br />Add the other nodes to the cluster and rebalance<br />Apache<br />Client-side Moxi<br />Cluster Mgmt.<br />Requests<br />DNS Entry<br />CouchbaseCluster<br />Couchbase<br />Couchbase<br />…<br />
  34. 34. Tribal Crossing: Deploying Couchbase in EC2<br />Web Server<br />Moxi figures out which node in the cluster holds data for a given key.<br />On each web server, install Moxi proxy<br />Start Moxi by pointing it to the DNS entry you created<br />Web apps connect to Moxi that is running locallymemcache->addServer(‘localhost’, 11211);<br />Apache<br />Client-side Moxi<br />Cluster Mgmt.<br />Requests<br />DNS Entry<br />CouchbaseCluster<br />Couchbase<br />Couchbase<br />…<br />
  35. 35. Tribal Crossing: Representing Game Data in Couchbase<br />Use case - simple farming game:<br />A player can have a variety of plants on their farm.<br />A player can add or remove plants from their farm.<br />A Player can see what plants are on another player's farm.<br />
  36. 36. Representing Objects<br />Simply treat an object as an associative array<br />Determine the key for an object using the class name (or type) of the object and an unique ID<br />Representing Object Lists<br />Denormalization<br />Save a comma separated list or an array of object IDs<br />Tribal Crossing: Representing Game Data in Couchbase<br />
  37. 37. Tribal Crossing: Representing Game Data in Couchbase<br />Player Object<br />Key: 'Player1'<br />Array<br />(<br /> [Id] => 1<br /> [Name] => Shawn<br />)<br />Plant Object<br />Key: 'Plant201'<br />Array<br />(<br /> [Id] => 201<br /> [Player_Id] => 1<br />[Name] => Starflower<br />)<br />PlayerPlant List<br />Key: 'Player1_PlantList'<br />Array<br />(<br /> [0] => 201<br /> [1] => 202<br /> [2] => 204<br />)<br />
  38. 38. No need to “ALTER TABLE”<br />Add new “fields” all objects at any time<br />Specify default value for missing fields<br />Increased development speed<br />Using JSON for data objects though, owing to the ability to query on arbitrary fields in Couchbase 2.0<br />Tribal Crossing: Schema-less Game Data<br />
  39. 39. Tribal Crossing: Accessing Game Data in Couchbase<br />Get all plants belong to a given player<br />Request: GET /player/1/farm<br />$plant_ids = couchbase->get('Player1_PlantList');<br />$response = array();<br />foreach ($plant_ids as $plant_id)<br />{<br /> $plant = couchbase->get('Plant' . $plant_id);<br /> $response[] = $plant;<br />}<br />echo json_encode($response);<br />
  40. 40. Give a player a new plant<br />// Create the new plant<br />$new_plant = array (<br /> 'id' => 100,<br /> 'name' => 'Mushroom'<br />);<br />$couchbase->set('Plant100', $new_plant);<br />// Update the player plant list<br />$plant_ids = $couchbase->get('Player1_PlantList');<br />$plant_ids[] = $new_plant['id'];<br />$couchbase->set('Player1_PlantList', $plant_ids);<br />Tribal Crossing: Modifying Game Data in Couchbase<br />
  41. 41. Concurrency issue can occur when multiple requests are working with the same piece of data.<br />Solution:<br />CAS (check-and-set)<br />Client can know if someone else has modified the data while you are trying to update<br />Implement optimistic concurrency control<br />Locking (try/wait cycle)<br />GETL (get with lock + timeout) operations<br />Pessimistic concurrency control<br />Tribal Crossing: Concurrency<br />
  42. 42. Record object relationships both ways<br />Example: Plots and Plants<br />Plot object stores id of the plant that it hosts<br />Plant object stores id of the plot that it grows on<br />Resolution in case of mismatch<br />Don't sweat the extra calls to load data in a one-to-many relationship<br />Use multiGet<br />We can still cache aggregated results in a Memcache bucket if needed<br />Tribal Crossing: Data Relationship<br />
  43. 43. First migrated large or slow performing tables and frequently updated fields from MySQL to Couchbase<br />Web Server<br />Tribal Crossing: Migrating to CouchbaseServers<br />Apache + PHP<br />Client-side Moxi<br />MySQL<br />memcached<br />protocol listener/sender<br />TAP<br />engine interface<br />Reporting Applications<br />TAP Client<br />Couchbase Storage Engine<br />
  44. 44. Tribal Crossing: Deployment <br />
  45. 45. Tribal Crossing: Deployment<br />
  46. 46. Significantly reduced the cost incurred by scaling up database servers and managing them.<br />Achieved significant improvements in various performance metrics (e.g., read, write, latency, etc.)<br />Allowed them to focus more on game development and optimizing key metrics<br />Plan to use real-time MapReduce, querying, and indexing abilities provided by the upcoming Elastic Couchbase 2.0<br />Tribal Crossing: Conclusion<br />
  47. 47. Introduction<br />What is Couchbase Server?<br />Simple, Fast, Elastic<br />Technology Overview (Architecture, data flow, rebalancing)<br />Tribal Crossing Inc: Animal Party<br />Challenges before Couchbase<br />Original Architecture<br />Why Couchbase?<br />Simplicity<br />Performance<br />Flexibility<br />Deploying Couchbase<br />New Architecture<br />EC2<br />Data Model<br />Accessing data in Couchbase<br />Product Roadmap<br />Q&A<br />Agenda<br />
  48. 48. Mobile to cloud data synchronization<br />Cross data center replication<br />Product Roadmap: Couchbase Server 2.0<br />US West Coast Data Center<br />US East Coast Data Center<br />CouchbaseServer<br />CouchbaseServer<br />CouchSync<br />CouchSync<br />CouchSync<br />Couchbase Single Server<br />Couchbase Single Server<br />CouchSync<br />CouchSync<br />…<br />…<br />…<br />…<br />…<br />…<br />…<br />
  49. 49. Replace Sqlite-based storage engine with CouchDB<br />Support indexing and querying on values<br />Integrate real-time MapReduce into Couchbase server<br />SDK for Couchbase server<br />Product Roadmap: Couchbase Server 2.0<br />Membase Server 1.7<br />CouchDB 1.1<br />Couchbase Server 2.0<br />The world’s leading caching and clustering technology<br />The fastest, most complete and most reliable database on the planet<br />The most reliable and full-featured document database<br />
  50. 50. Community Edition<br />Open source build<br />Free forum support<br />Enterprise Edition<br />Free for non-production use<br />Certified, QA tested version of open source<br />Case tracking and guaranteed SLA for production environments<br />Partner in Korea<br />N2M Inc. (http://www.n2m.co.kr)<br />CouchbaseProduct Download<br />
  51. 51. Q&A<br />Matt Ingenthron, Couchbase Inc.<br />(matt@couchbase.com, @ingenthr)<br />Chiyoung Seo, Couchbase Inc.<br />(chiyoung@couchbase.com, @chiyoungseo)<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×