SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
Couchbase	
  Server	
  and	
  node.js	
  



Full	
  Stack	
  JSON
Philipp	
  Fehre	
  
Developer	
  Evangelist,	
  Couchbase,	
  Inc.
Who	
  am	
  I?
Ex-­‐Consultant	
  of	
  many	
  projects	
  
NoSQL	
  Database	
  guy	
  of	
  many	
  Databases	
  
Open	
  Source	
  Enthusiast	
  of	
  many	
  lines	
  of	
  code	
  
JavaScripting	
  Rubyist
What	
  do	
  we	
  need	
  for	
  a	
  Game?
Requirements	
  for	
  a	
  Game	
  API
• RESTful,	
  probably	
  JSON	
  interface	
  for	
  stateful	
  data	
  
• SPEED!!!	
  
Users	
  are	
  fickle.	
  	
  Remember	
  that	
  fetching	
  a	
  data	
  item	
  is	
  inherently	
  
synchronous.	
  
• Ability	
  to	
  Scale	
  
True	
  social	
  games	
  need	
  state,	
  and	
  scale	
  
Scale	
  means	
  scale	
  up	
  and	
  scale	
  down	
  
• Efficiency	
  
Let’s	
  be	
  honest,	
  most	
  players	
  are	
  free	
  players.	
  	
  However,	
  we	
  need	
  
free	
  players	
  to	
  get	
  the	
  scale	
  we	
  need	
  to	
  get	
  enough	
  pay	
  players.
How	
  Do	
  We	
  Get	
  There?
node.js	
  
• REST	
  is	
  native	
  
HTTP	
  is	
  native!	
  
JSON	
  is	
  native!	
  
• Event	
  driven	
  programming	
  model	
  
Leads	
  your	
  software	
  development	
  to	
  be	
  fast	
  
• Scale	
  out	
  ready	
  
Because	
  of	
  the	
  loose	
  coupling,	
  node	
  can	
  scale	
  out	
  as	
  far	
  as	
  you	
  have	
  machines	
  
However,	
  this	
  means	
  it	
  needs	
  Couchbase	
  
• Very	
  efficient	
  use	
  of	
  system	
  resources	
  
Single	
  threaded	
  but	
  multi-­‐process,	
  event	
  driven	
  model	
  ensures	
  good	
  handoff	
  
from	
  compute	
  to	
  IO
Couchbase	
  
• Document	
  database	
  
Designed	
  for	
  JSON	
  
• Sub-­‐millisecond	
  latency	
  
Gives	
  you	
  the	
  consistent	
  performance	
  needed	
  to	
  build	
  complex,	
  interactive	
  
game	
  play	
  
• Designed	
  for	
  Scale	
  
Add	
  and	
  remove	
  nodes	
  as	
  needed	
  
• Efficiency	
  
Couchbase	
  manages	
  system	
  resources	
  such	
  as	
  memory	
  and	
  CPU	
  efficiently
JSON	
  
we	
  all	
  know	
  and	
  love
JSON	
  in	
  node.js
/* $ cat example.json
* {
* "foo": "bar"
* }
*/
!
var fs = require("fs");
var rawData = fs.readFileSync("./example.json");
var data = JSON.parse(rawData);
console.log("property foo of data:", data.foo);
!
/* $ node read.js
* property for of data: bar
*/
Couchbase	
  &	
  JSON
JSON	
  &	
  Couchbase
• Native	
  Data	
  format	
  
Special	
  support	
  for	
  JSON	
  documents	
  is	
  provided	
  
Couchbase	
  recognises	
  JSON	
  as	
  a	
  Datatype	
  
• Complex	
  queries	
  
JSON	
  can	
  be	
  handled	
  by	
  the	
  View	
  engine	
  
Build	
  indices	
  via	
  Map	
  /	
  Reduce
Couchbase	
  Views
JSON	
  as	
  the	
  API
curl	
  https://api.github.com/users/sideshowcoder
{
"login": "sideshowcoder",
"id": 108488,
"avatar_url": "https://avatars.githubusercontent.com/u/…",
"gravatar_id": "5cde19029032f151ca09687f7c8783eb",
"url": "https://api.github.com/users/sideshowcoder",
"html_url": "https://github.com/sideshowcoder",
"followers_url": "https://api.github.com/users/…",
"following_url": "https://api.github.com/users/…",
...
}
JSON	
  in	
  the	
  Browser
<html>
<body>
<script src="/jquery-1.11.0.min.js"></script>
<div id="user-name"></div>
<div id="last-active"></div>
<script>
$.getJSON("https://api.github.com/users/sideshowcoder",
function (data) {
$("#user-name").text(data.login);
$("#last-active").text(data.updated_at);
})
</script>
</body>
</html>
JavaScript	
  is	
  the	
  
Programming	
  Language	
  
of	
  the	
  Web
DEMO
Building	
  an	
  API	
  
with	
  Couchbase,	
  node.js,	
  and	
  AngularJS
Users
signup	
  /	
  signin	
  /	
  signout	
  
Keying
•Use	
  a	
  Unique	
  value	
  for	
  key	
  (email,	
  username,	
  sku,	
  isbn,	
  etc.)	
  
example	
  u::phil	
  
•Predictable	
  Keys	
  can	
  follow	
  Key-­‐Value	
  pa[erns	
  
Users	
  typically	
  can	
  be	
  done	
  this	
  way	
  and	
  are	
  the	
  most	
  numerous	
  items
The	
  Database
Smart	
  client
Reuse	
  your	
  database	
  connection
Connecting	
  to	
  Couchbase
var _db = null;
!
var db = function (cb) {
if (_db) return cb(null, _db);
_db = new couchbase.Connection(dbConfig, function(err) {
if (err) return cb(err);
cb(null, _db);
})
}
Creating	
  a	
  new	
  user
Add	
  
User	
  Datamodel	
  	
  
Serialisation
Authentication
Loading	
  is	
  quick	
  
use	
  Bcrypt
Game	
  State
Routes
Question	
  List
Be	
  lazy	
  we	
  expect	
  free	
  users	
  
Don’t	
  overwrite	
  by	
  accident	
  
Referential	
  Keys
Consistent	
  Data
Couchbase	
  is	
  a	
  CP	
  System
Dealing	
  with	
  concurrency
• Other	
  users	
  are	
  ratings	
  beers	
  also,	
  so	
  we	
  use	
  a	
  CAS	
  update	
  
we	
  don’t	
  want	
  to	
  accidentally	
  overwrite	
  another	
  users	
  rating	
  that	
  is	
  being	
  saved	
  
at	
  the	
  same	
  time	
  as	
  ours	
  
• Retry	
  the	
  operation,	
  if	
  appropriate	
  
Also	
  useful	
  if	
  you	
  have	
  internal	
  structure	
  that	
  you	
  want	
  to	
  maintain
Actor	
  1 Actor	
  2
Couchbase	
  Server
CAS	
  mismatch	
  
&	
  retry
Success
The	
  Frontend
Rendering	
  JSON	
  responses
Using	
  response	
  data	
  directly
One	
  more	
  thing
Showing	
  the	
  answer	
  count
Couchbase	
  map	
  reduce	
  in	
  action
Couchbase	
  Views
http://localhost:9000/index.html?
na#sec=views&viewsBucket=default
Development	
  vs.	
  Production	
  Views
• Development	
  views	
  index	
  a	
  
subset	
  of	
  the	
  data.	
  
• Publishing	
  a	
  view	
  builds	
  the	
  
index	
  across	
  the	
  entire	
  
cluster.	
  
• Queries	
  on	
  production	
  
views	
  are	
  scattered	
  to	
  all	
  
cluster	
  members	
  and	
  
results	
  are	
  gathered	
  and	
  
returned	
  to	
  the	
  client.
Eventual	
  Persistence
Storage	
  to	
  Index
Couchbase Server
EP EngineRAM Cache
Disk Write Queue
Replication Queue
View Engine
Indexers
Application Server
storage ops
Replica Couchbase Cluster Machine
When	
  to	
  use	
  and	
  when	
  not	
  to	
  use
• views	
  operate	
  on	
  the	
  persisted	
  data	
  
• don’t	
  use	
  for	
  “login”	
  
• data	
  can	
  be	
  “stale”	
  
Counts	
  and	
  alike	
  are	
  ok	
  to	
  be	
  stale
Creating	
  views	
  with	
  code
Querying	
  the	
  View
FINAL	
  DEMO
Links
• https://github.com/couchbaselabs/node-­‐couch-­‐qa	
  
• https://github.com/couchbase/couchnode	
  
• https://blog.couchbase.com/game-­‐servers-­‐and-­‐couchbase-­‐nodejs-­‐part-­‐1	
  
• https://blog.couchbase.com/game-­‐servers-­‐and-­‐couchbase-­‐nodejs-­‐part-­‐2	
  
• https://blog.couchbase.com/game-­‐servers-­‐and-­‐couchbase-­‐nodejs-­‐part-­‐3	
  
• https://github.com/brett19/node-­‐gameapi
Thank	
  you!
philipp@couchbase.com	
  
!
github:	
  @sideshowcoder	
  
twitter:	
  @ischi	
  
web:	
  sideshowcoder.com
Node.js and couchbase   Full Stack JSON - Munich NoSQL

Contenu connexe

Tendances

Kafka Connect - debezium
Kafka Connect - debeziumKafka Connect - debezium
Kafka Connect - debeziumKasun Don
 
Tech Spark Presentation
Tech Spark PresentationTech Spark Presentation
Tech Spark PresentationStephen Borg
 
Ansible for large scale deployment
Ansible for large scale deploymentAnsible for large scale deployment
Ansible for large scale deploymentKarthik .P.R
 
Migrating with Debezium
Migrating with DebeziumMigrating with Debezium
Migrating with DebeziumMike Fowler
 
Real time dashboards with Kafka and Druid
Real time dashboards with Kafka and DruidReal time dashboards with Kafka and Druid
Real time dashboards with Kafka and DruidVenu Ryali
 
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...rhatr
 
Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016
Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016 Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016
Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016 Lucas Jellema
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)Karthik .P.R
 
Introducing Venice
Introducing VeniceIntroducing Venice
Introducing VeniceYan Yan
 
Perfect Norikra 2nd Season
Perfect Norikra 2nd SeasonPerfect Norikra 2nd Season
Perfect Norikra 2nd SeasonSATOSHI TAGOMORI
 
Building a derived data store using Kafka
Building a derived data store using KafkaBuilding a derived data store using Kafka
Building a derived data store using KafkaVenu Ryali
 
Change Data Capture using Kafka
Change Data Capture using KafkaChange Data Capture using Kafka
Change Data Capture using KafkaAkash Vacher
 
Presto @ Treasure Data - Presto Meetup Boston 2015
Presto @ Treasure Data - Presto Meetup Boston 2015Presto @ Treasure Data - Presto Meetup Boston 2015
Presto @ Treasure Data - Presto Meetup Boston 2015Taro L. Saito
 
Embracing Database Diversity with Kafka and Debezium
Embracing Database Diversity with Kafka and DebeziumEmbracing Database Diversity with Kafka and Debezium
Embracing Database Diversity with Kafka and DebeziumFrank Lyaruu
 
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...Fwdays
 
Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...
Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...
Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...confluent
 
Column and hadoop
Column and hadoopColumn and hadoop
Column and hadoopAlex Jiang
 
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"IT Event
 
Clickhouse at Cloudflare. By Marek Vavrusa
Clickhouse at Cloudflare. By Marek VavrusaClickhouse at Cloudflare. By Marek Vavrusa
Clickhouse at Cloudflare. By Marek VavrusaValery Tkachenko
 

Tendances (20)

Kafka Connect - debezium
Kafka Connect - debeziumKafka Connect - debezium
Kafka Connect - debezium
 
Tech Spark Presentation
Tech Spark PresentationTech Spark Presentation
Tech Spark Presentation
 
Ansible for large scale deployment
Ansible for large scale deploymentAnsible for large scale deployment
Ansible for large scale deployment
 
Migrating with Debezium
Migrating with DebeziumMigrating with Debezium
Migrating with Debezium
 
Real time dashboards with Kafka and Druid
Real time dashboards with Kafka and DruidReal time dashboards with Kafka and Druid
Real time dashboards with Kafka and Druid
 
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
Building Google-in-a-box: using Apache SolrCloud and Bigtop to index your big...
 
Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016
Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016 Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016
Soaring through the Clouds - Oracle Fusion Middleware Partner Forum 2016
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)
 
Introducing Venice
Introducing VeniceIntroducing Venice
Introducing Venice
 
Perfect Norikra 2nd Season
Perfect Norikra 2nd SeasonPerfect Norikra 2nd Season
Perfect Norikra 2nd Season
 
Building a derived data store using Kafka
Building a derived data store using KafkaBuilding a derived data store using Kafka
Building a derived data store using Kafka
 
Cassandra in e-commerce
Cassandra in e-commerceCassandra in e-commerce
Cassandra in e-commerce
 
Change Data Capture using Kafka
Change Data Capture using KafkaChange Data Capture using Kafka
Change Data Capture using Kafka
 
Presto @ Treasure Data - Presto Meetup Boston 2015
Presto @ Treasure Data - Presto Meetup Boston 2015Presto @ Treasure Data - Presto Meetup Boston 2015
Presto @ Treasure Data - Presto Meetup Boston 2015
 
Embracing Database Diversity with Kafka and Debezium
Embracing Database Diversity with Kafka and DebeziumEmbracing Database Diversity with Kafka and Debezium
Embracing Database Diversity with Kafka and Debezium
 
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
Виталий Бондаренко "Fast Data Platform for Real-Time Analytics. Architecture ...
 
Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...
Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...
Billions of Messages in Real Time: Why Paypal & LinkedIn Trust an Engagement ...
 
Column and hadoop
Column and hadoopColumn and hadoop
Column and hadoop
 
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
Volodymyr Lyubinets "Introduction to big data processing with Apache Spark"
 
Clickhouse at Cloudflare. By Marek Vavrusa
Clickhouse at Cloudflare. By Marek VavrusaClickhouse at Cloudflare. By Marek Vavrusa
Clickhouse at Cloudflare. By Marek Vavrusa
 

Similaire à Node.js and couchbase Full Stack JSON - Munich NoSQL

Experiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamExperiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamBrian Benz
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Data saturday malta - ADX Azure Data Explorer overview
Data saturday malta - ADX Azure Data Explorer overviewData saturday malta - ADX Azure Data Explorer overview
Data saturday malta - ADX Azure Data Explorer overviewRiccardo Zamana
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
SQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsSQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsMike Broberg
 
Intro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with sparkIntro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with sparkAlex Zeltov
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftArun Gupta
 
Node.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQ
Node.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQNode.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQ
Node.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQJoshua Miller
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1Mohammad Qureshi
 
Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for OpenstackMohit Sethi
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014Brian Cavalier
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...
Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...
Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...viirya
 
Power BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle CloudPower BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle CloudKellyn Pot'Vin-Gorman
 
Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Arun Gupta
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on RailsAvi Kedar
 

Similaire à Node.js and couchbase Full Stack JSON - Munich NoSQL (20)

Experiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure teamExperiences using CouchDB inside Microsoft's Azure team
Experiences using CouchDB inside Microsoft's Azure team
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Data saturday malta - ADX Azure Data Explorer overview
Data saturday malta - ADX Azure Data Explorer overviewData saturday malta - ADX Azure Data Explorer overview
Data saturday malta - ADX Azure Data Explorer overview
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Node.js
Node.jsNode.js
Node.js
 
SQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 QuestionsSQL to NoSQL: Top 6 Questions
SQL to NoSQL: Top 6 Questions
 
Chef for openstack
Chef for openstackChef for openstack
Chef for openstack
 
Intro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with sparkIntro to big data analytics using microsoft machine learning server with spark
Intro to big data analytics using microsoft machine learning server with spark
 
Ml2
Ml2Ml2
Ml2
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
 
Node.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQ
Node.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQNode.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQ
Node.CQ - Creating Real-time Data Mashups with Node.JS and Adobe CQ
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Chef for Openstack
Chef for OpenstackChef for Openstack
Chef for Openstack
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014Differential Sync and JSON Patch @ SpringOne2GX 2014
Differential Sync and JSON Patch @ SpringOne2GX 2014
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...
Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...
Speed up Interactive Analytic Queries over Existing Big Data on Hadoop with P...
 
Power BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle CloudPower BI with Essbase in the Oracle Cloud
Power BI with Essbase in the Oracle Cloud
 
Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 

Plus de Philipp Fehre

node.js and native code extensions by example
node.js and native code extensions by examplenode.js and native code extensions by example
node.js and native code extensions by examplePhilipp Fehre
 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a databasePhilipp Fehre
 
Couchbase Mobile on Android
Couchbase Mobile on AndroidCouchbase Mobile on Android
Couchbase Mobile on AndroidPhilipp Fehre
 
You got schema in my json
You got schema in my jsonYou got schema in my json
You got schema in my jsonPhilipp Fehre
 
What is new in Riak 2.0
What is new in Riak 2.0What is new in Riak 2.0
What is new in Riak 2.0Philipp Fehre
 
Ember background basics
Ember background basicsEmber background basics
Ember background basicsPhilipp Fehre
 
Ember learn from Riak Control
Ember learn from Riak ControlEmber learn from Riak Control
Ember learn from Riak ControlPhilipp Fehre
 
Something about node basics
Something about node basicsSomething about node basics
Something about node basicsPhilipp Fehre
 
A little more advanced node
A little more advanced nodeA little more advanced node
A little more advanced nodePhilipp Fehre
 
Something about node in the realworld
Something about node in the realworldSomething about node in the realworld
Something about node in the realworldPhilipp Fehre
 
Riak Intro at Munich Node.js
Riak Intro at Munich Node.jsRiak Intro at Munich Node.js
Riak Intro at Munich Node.jsPhilipp Fehre
 
PUT Knowledge BUCKET Brain KEY Riak
PUT Knowledge BUCKET Brain KEY RiakPUT Knowledge BUCKET Brain KEY Riak
PUT Knowledge BUCKET Brain KEY RiakPhilipp Fehre
 
Campfire bot lightning talk
Campfire bot lightning talkCampfire bot lightning talk
Campfire bot lightning talkPhilipp Fehre
 
Lighting fast rails with zeus
Lighting fast rails with zeusLighting fast rails with zeus
Lighting fast rails with zeusPhilipp Fehre
 
JavaScript frontend testing from failure to good to great
JavaScript frontend testing from failure to good to greatJavaScript frontend testing from failure to good to great
JavaScript frontend testing from failure to good to greatPhilipp Fehre
 

Plus de Philipp Fehre (19)

node.js and native code extensions by example
node.js and native code extensions by examplenode.js and native code extensions by example
node.js and native code extensions by example
 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a database
 
Couchbase Mobile on Android
Couchbase Mobile on AndroidCouchbase Mobile on Android
Couchbase Mobile on Android
 
From 0 to syncing
From 0 to syncingFrom 0 to syncing
From 0 to syncing
 
You got schema in my json
You got schema in my jsonYou got schema in my json
You got schema in my json
 
What is new in Riak 2.0
What is new in Riak 2.0What is new in Riak 2.0
What is new in Riak 2.0
 
Ember background basics
Ember background basicsEmber background basics
Ember background basics
 
Ember learn from Riak Control
Ember learn from Riak ControlEmber learn from Riak Control
Ember learn from Riak Control
 
Testing tdd jasmine
Testing tdd jasmineTesting tdd jasmine
Testing tdd jasmine
 
Testing tdd dom
Testing tdd domTesting tdd dom
Testing tdd dom
 
Something about node basics
Something about node basicsSomething about node basics
Something about node basics
 
A little more advanced node
A little more advanced nodeA little more advanced node
A little more advanced node
 
Something about node in the realworld
Something about node in the realworldSomething about node in the realworld
Something about node in the realworld
 
Riak Intro at Munich Node.js
Riak Intro at Munich Node.jsRiak Intro at Munich Node.js
Riak Intro at Munich Node.js
 
PUT Knowledge BUCKET Brain KEY Riak
PUT Knowledge BUCKET Brain KEY RiakPUT Knowledge BUCKET Brain KEY Riak
PUT Knowledge BUCKET Brain KEY Riak
 
Campfire bot lightning talk
Campfire bot lightning talkCampfire bot lightning talk
Campfire bot lightning talk
 
Lighting fast rails with zeus
Lighting fast rails with zeusLighting fast rails with zeus
Lighting fast rails with zeus
 
JavaScript frontend testing from failure to good to great
JavaScript frontend testing from failure to good to greatJavaScript frontend testing from failure to good to great
JavaScript frontend testing from failure to good to great
 
Network with node
Network with nodeNetwork with node
Network with node
 

Dernier

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Dernier (20)

Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Node.js and couchbase Full Stack JSON - Munich NoSQL

  • 1.
  • 2. Couchbase  Server  and  node.js  
 
 Full  Stack  JSON Philipp  Fehre   Developer  Evangelist,  Couchbase,  Inc.
  • 3. Who  am  I? Ex-­‐Consultant  of  many  projects   NoSQL  Database  guy  of  many  Databases   Open  Source  Enthusiast  of  many  lines  of  code   JavaScripting  Rubyist
  • 4. What  do  we  need  for  a  Game?
  • 5. Requirements  for  a  Game  API • RESTful,  probably  JSON  interface  for  stateful  data   • SPEED!!!   Users  are  fickle.    Remember  that  fetching  a  data  item  is  inherently   synchronous.   • Ability  to  Scale   True  social  games  need  state,  and  scale   Scale  means  scale  up  and  scale  down   • Efficiency   Let’s  be  honest,  most  players  are  free  players.    However,  we  need   free  players  to  get  the  scale  we  need  to  get  enough  pay  players.
  • 6. How  Do  We  Get  There?
  • 7. node.js   • REST  is  native   HTTP  is  native!   JSON  is  native!   • Event  driven  programming  model   Leads  your  software  development  to  be  fast   • Scale  out  ready   Because  of  the  loose  coupling,  node  can  scale  out  as  far  as  you  have  machines   However,  this  means  it  needs  Couchbase   • Very  efficient  use  of  system  resources   Single  threaded  but  multi-­‐process,  event  driven  model  ensures  good  handoff   from  compute  to  IO
  • 8. Couchbase   • Document  database   Designed  for  JSON   • Sub-­‐millisecond  latency   Gives  you  the  consistent  performance  needed  to  build  complex,  interactive   game  play   • Designed  for  Scale   Add  and  remove  nodes  as  needed   • Efficiency   Couchbase  manages  system  resources  such  as  memory  and  CPU  efficiently
  • 9. JSON   we  all  know  and  love
  • 10. JSON  in  node.js /* $ cat example.json * { * "foo": "bar" * } */ ! var fs = require("fs"); var rawData = fs.readFileSync("./example.json"); var data = JSON.parse(rawData); console.log("property foo of data:", data.foo); ! /* $ node read.js * property for of data: bar */
  • 12. JSON  &  Couchbase • Native  Data  format   Special  support  for  JSON  documents  is  provided   Couchbase  recognises  JSON  as  a  Datatype   • Complex  queries   JSON  can  be  handled  by  the  View  engine   Build  indices  via  Map  /  Reduce
  • 14. JSON  as  the  API curl  https://api.github.com/users/sideshowcoder { "login": "sideshowcoder", "id": 108488, "avatar_url": "https://avatars.githubusercontent.com/u/…", "gravatar_id": "5cde19029032f151ca09687f7c8783eb", "url": "https://api.github.com/users/sideshowcoder", "html_url": "https://github.com/sideshowcoder", "followers_url": "https://api.github.com/users/…", "following_url": "https://api.github.com/users/…", ... }
  • 15. JSON  in  the  Browser <html> <body> <script src="/jquery-1.11.0.min.js"></script> <div id="user-name"></div> <div id="last-active"></div> <script> $.getJSON("https://api.github.com/users/sideshowcoder", function (data) { $("#user-name").text(data.login); $("#last-active").text(data.updated_at); }) </script> </body> </html>
  • 16. JavaScript  is  the   Programming  Language   of  the  Web
  • 17. DEMO
  • 18. Building  an  API   with  Couchbase,  node.js,  and  AngularJS
  • 19. Users signup  /  signin  /  signout  
  • 20. Keying •Use  a  Unique  value  for  key  (email,  username,  sku,  isbn,  etc.)   example  u::phil   •Predictable  Keys  can  follow  Key-­‐Value  pa[erns   Users  typically  can  be  done  this  way  and  are  the  most  numerous  items
  • 22. Smart  client Reuse  your  database  connection
  • 23. Connecting  to  Couchbase var _db = null; ! var db = function (cb) { if (_db) return cb(null, _db); _db = new couchbase.Connection(dbConfig, function(err) { if (err) return cb(err); cb(null, _db); }) }
  • 24. Creating  a  new  user Add   User  Datamodel     Serialisation
  • 27. Question  List Be  lazy  we  expect  free  users   Don’t  overwrite  by  accident   Referential  Keys
  • 28. Consistent  Data Couchbase  is  a  CP  System
  • 29. Dealing  with  concurrency • Other  users  are  ratings  beers  also,  so  we  use  a  CAS  update   we  don’t  want  to  accidentally  overwrite  another  users  rating  that  is  being  saved   at  the  same  time  as  ours   • Retry  the  operation,  if  appropriate   Also  useful  if  you  have  internal  structure  that  you  want  to  maintain Actor  1 Actor  2 Couchbase  Server CAS  mismatch   &  retry Success
  • 31. Rendering  JSON  responses Using  response  data  directly
  • 33. Showing  the  answer  count Couchbase  map  reduce  in  action
  • 35. Development  vs.  Production  Views • Development  views  index  a   subset  of  the  data.   • Publishing  a  view  builds  the   index  across  the  entire   cluster.   • Queries  on  production   views  are  scattered  to  all   cluster  members  and   results  are  gathered  and   returned  to  the  client.
  • 37. Storage  to  Index Couchbase Server EP EngineRAM Cache Disk Write Queue Replication Queue View Engine Indexers Application Server storage ops Replica Couchbase Cluster Machine
  • 38. When  to  use  and  when  not  to  use • views  operate  on  the  persisted  data   • don’t  use  for  “login”   • data  can  be  “stale”   Counts  and  alike  are  ok  to  be  stale
  • 42. Links • https://github.com/couchbaselabs/node-­‐couch-­‐qa   • https://github.com/couchbase/couchnode   • https://blog.couchbase.com/game-­‐servers-­‐and-­‐couchbase-­‐nodejs-­‐part-­‐1   • https://blog.couchbase.com/game-­‐servers-­‐and-­‐couchbase-­‐nodejs-­‐part-­‐2   • https://blog.couchbase.com/game-­‐servers-­‐and-­‐couchbase-­‐nodejs-­‐part-­‐3   • https://github.com/brett19/node-­‐gameapi
  • 43. Thank  you! philipp@couchbase.com   ! github:  @sideshowcoder   twitter:  @ischi   web:  sideshowcoder.com