Frictionless Persistence in.net with MongoDB. Mogens Heller Grabe Trifork mhg@trifork.com



Similar documents
MongoDB in the NoSQL and SQL world. Horst Rechner Berlin,

NoSQL replacement for SQLite (for Beatstream) Antti-Jussi Kovalainen Seminar OHJ-1860: NoSQL databases

Getting Started with MongoDB

MongoDB Developer and Administrator Certification Course Agenda

MONGODB - THE NOSQL DATABASE

Document Oriented Database

NOSQL INTRODUCTION WITH MONGODB AND RUBY GEOFF

Big Data Solutions. Portal Development with MongoDB and Liferay. Solutions

CSCC09F Programming on the Web. Mongo DB

Building Your First MongoDB Application

NoSQL Databases. Nikos Parlavantzas

Why NoSQL? Your database options in the new non- relational world IBM Cloudant 1

Big Data & Data Science Course Example using MapReduce. Presented by Juan C. Vega

Cloud Powered Mobile Apps with Azure

NoSQL web apps. w/ MongoDB, Node.js, AngularJS. Dr. Gerd Jungbluth, NoSQL UG Cologne,

L7_L10. MongoDB. Big Data and Analytics by Seema Acharya and Subhashini Chellappan Copyright 2015, WILEY INDIA PVT. LTD.

Cloud Scale Distributed Data Storage. Jürmo Mehine

MongoDB. An introduction and performance analysis. Seminar Thesis

NoSQL Database - mongodb

An Approach to Implement Map Reduce with NoSQL Databases

.NET User Group Bern

Perl & NoSQL Focus on MongoDB. Jean-Marie Gouarné jmgdoc@cpan.org

Structured Data Storage

Scaling up = getting a better machine. Scaling out = use another server and add it to your cluster.

Introduction to NoSQL and MongoDB. Kathleen Durant Lesson 20 CS 3200 Northeastern University

NoSQL: Going Beyond Structured Data and RDBMS

MongoDB: document-oriented database

Big Data. Facebook Wall Data using Graph API. Presented by: Prashant Patel Jaykrushna Patel

HO5604 Deploying MongoDB. A Scalable, Distributed Database with SUSE Cloud. Alejandro Bonilla. Sales Engineer abonilla@suse.com

these three NoSQL databases because I wanted to see a the two different sides of the CAP

nosql and Non Relational Databases

Hacettepe University Department Of Computer Engineering BBM 471 Database Management Systems Experiment

Analytics March 2015 White paper. Why NoSQL? Your database options in the new non-relational world

Comparison of the Frontier Distributed Database Caching System with NoSQL Databases

NoSQL - What we ve learned with mongodb. Paul Pedersen, Deputy CTO paul@10gen.com DAMA SF December 15, 2011

Scaling with MongoDB. by Michael Schurter Scaling with MongoDB by Michael Schurter - OS Bridge,

Assignment # 1 (Cloud Computing Security)

SURVEY ON MONGODB: AN OPEN- SOURCE DOCUMENT DATABASE

Dr. Chuck Cartledge. 15 Oct. 2015

Certified MongoDB Professional VS-1058

MongoDB. Or how I learned to stop worrying and love the database. Mathias Stearn. N*SQL Berlin October 22th, gen

NoSQL Databases. Polyglot Persistence

Please ask questions! Have people used non-relational dbs before? MongoDB?

Data Model Design for MongoDB

MongoDB. The Definitive Guide to. The NoSQL Database for Cloud and Desktop Computing. Apress8. Eelco Plugge, Peter Membrey and Tim Hawkins

Introducing DocumentDB

The MongoDB Tutorial Introduction for MySQL Users. Stephane Combaudon April 1st, 2014

PHP and MongoDB Web Development Beginners Guide by Rubayeet Islam

Application of NoSQL Database in Web Crawling

An Open Source NoSQL solution for Internet Access Logs Analysis

Domain driven design, NoSQL and multi-model databases

Slave. Master. Research Scholar, Bharathiar University

WHAT IS AN APPLICATION PLATFORM?

3 Case Studies of NoSQL and Java Apps in the Real World

MongoDB and Couchbase

Databases for text storage

WINDOWS AZURE DATA MANAGEMENT AND BUSINESS ANALYTICS

SQL VS. NO-SQL. Adapted Slides from Dr. Jennifer Widom from Stanford

Preparing Your Data For Cloud

NoSQL in der Cloud Why? Andreas Hartmann

Microsoft Azure Data Technologies: An Overview

Understanding NoSQL on Microsoft Azure

Database Management System Choices. Introduction To Database Systems CSE 373 Spring 2013

Understanding NoSQL Technologies on Windows Azure

Big data and urban mobility

Cloud Powered Mobile Apps with Microsoft Azure

Open Source Technologies on Microsoft Azure

Architecting Open source solutions on Azure. Nicholas Dritsas Senior Director, Microsoft Singapore

Attacking MongoDB. Firstov Mihail

Cloud Computing with Windows Azure using your Preferred Technology

extensible record stores document stores key-value stores Rick Cattel s clustering from Scalable SQL and NoSQL Data Stores SIGMOD Record, 2010

Windows Azure Storage Scaling Cloud Storage Andrew Edwards Microsoft

Predictive Research Inc., Predict & Benefit

SharePoint Comparison of Features

Overview of Databases On MacOS. Karl Kuehn Automation Engineer RethinkDB

THE SEMANTIC WEB AND IT`S APPLICATIONS

Brad Dayley. NoSQL with MongoDB

Sentimental Analysis using Hadoop Phase 2: Week 2

Building a RESTful service with MongoDB and Spring MVC

Can the Elephants Handle the NoSQL Onslaught?

In Memory Accelerator for MongoDB

Time series IoT data ingestion into Cassandra using Kaa

How To Write A Nosql Database In Spring Data Project

NoSQL Databases. Institute of Computer Science Databases and Information Systems (DBIS) DB 2, WS 2014/2015

BIG DATA ANALYTICS REFERENCE ARCHITECTURES AND CASE STUDIES

Lecture Data Warehouse Systems

Advanced Data Management Technologies

BASHO DATA PLATFORM SIMPLIFIES BIG DATA, IOT, AND HYBRID CLOUD APPS

How SourceForge is Using MongoDB

The NoSQL Ecosystem, Relaxed Consistency, and Snoop Dogg. Adam Marcus MIT CSAIL

Building Internet of Things Apps with Cloudant DBaaS. Andy Ellicott, Cloudant John David Chibuk, Kiwi Wearables

Microsoft Big Data Solutions. Anar Taghiyev P-TSP

Integrating Big Data into the Computing Curricula

Transcription:

Frictionless Persistence in.net with MongoDB Mogens Heller Grabe Trifork mhg@trifork.com

Agenda Document-oriented databases Introduction to MongoDB JavaScript, baby! How to do it with C# Tiny web app sample Some (grander) usage scenarios Who s using it Frictionless Persistence in.net 22

Goals Communicate that NoSQL can relieve us of some of the pain we re experiencing Spread the word that NoSQL is also very relevant to people engaged in enterprisey platforms in enterprisey environments Allow for just enough understanding of MongoDB to allow it to be considered as a possible future technology choice Frictionless Persistence in.net 33

Who might be interested? Developer who doesn t know too much about MongoDB feels the relational agony is interested in technologies with an agile mindset s not necessarily a C# dude (but there will be C# ) Frictionless Persistence in.net 44

Who am I? { } name: Mogens Heller Grabe, occupation: Software Pilot @ Trifork, preferences: { likes: [ CLR, OSS, Building great stuff for customers, node.js, Ruby, (...) ], dislikes: [ Pain, Geeky introductions ] }, contact_info: { email: mhg@trifork.com, twitter: mookid8000, blog: http://mookid.dk/oncode } Frictionless Persistence in.net 55

An experiment... If you carry some kind of mobile, webenabled device, and you have a question: http://priorityq.apphb.com go here and ask a question and/or vote on other questions (or if you feel like voting on other people s questions) Frictionless Persistence in.net 66

First, a few words about DOCUMENT-ORIENTED DATABASES Frictionless Persistence in.net 77

Document DBs Store documents... Object SomeField AnotherField AnotherObject WithFields 1 * YetAnotherObject 1...* OhMy AndSoOn Frictionless Persistence in.net 88

Document DBs Common properties Schemaless/dynamic No joins Unit of atomicity: One document Can be distributed Quite performant Frictionless Persistence in.net 99

DocumentDBs Document-oriented databases Lotus Notes CouchDB MongoDB RavenDB SimpleDB Redis Riak (...etc...etc...etc...) Frictionless Persistence in.net 10

Now it s about time we get an INTRODUCTION TO MONGODB Frictionless Persistence in.net 11

MongoDB overview MongoDB as in humongous, not retarded... Developed (and commercially supported) by 10Gen Free and open source Currently in a stable 1.8.1 (odd minor version numbers are development versions) Frictionless Persistence in.net 12

MongoDB overview Document-oriented database like CouchDB, RavenDB, and many others Stores JSON (Binary json actually, BSON) i.e. there s no fixed schema Unlike most document dbs, MongoDB can be ad hoc queried perform in-place updates (i.e. it can modify documents on the server) is NOT REST-based (can expose a REST endpoint though) Frictionless Persistence in.net 13

Data organization Mongo DB1 Collection1 Collection2 DB2 Collection1 Collection2 Instance Database Collection Document Snowflakes idea ripped from MongoDB The Definitive Guide Frictionless Persistence in.net 14

Features Ad hoc querying Indexes Normal, as well as geo-spatial Server-side updates Map/reduce we ll take a peek at these things today... Simple map/reduce implementation allows for computations that aggregate across documents and embedded documents GridFS Standard for streaming large blobs of data to/from documents Durability Either through replication or through journaling (1.8+) Scalability and fault tolerance via auto-sharding and replica sets Frictionless Persistence in.net 15

Documents, queries, updates Documents are JSON {_id: ObjectId(.. ), user_name: joe } Queries are documents {user_name: joe } {user_name: /^joe.*/} {user_name: {$in: [ joe, moe ]}} Updates are documents {_id: 21, user_name: joe, txt: bla } {$inc: {hits: 1}} {$addtoset: {tags: new_tag_to_add }} Frictionless Persistence in.net 16

Let s see... DEMO Install MongoDB Connect with Mongo Shell Create db with collection Query, update, query Query, explain, index, explain Frictionless Persistence in.net 17

Let s try and compare... DEMO Install Microsoft SQL Server Connect with SQL Server Management Studio Create db with table Query, update, index, query Frictionless Persistence in.net 18

Now let s take a look at HOW TO DO IT WITH C# Frictionless Persistence in.net 19

MongoDB and.net Available.NET drivers Official mongo-csharp Community NoRM mongodb-csharp simple-mongodb (...) Frictionless Persistence in.net 20

Official driver: mongo-csharp Two parts: MongoDB.Driver Connect and manage the db Interact with raw documents MongoDB.Bson BSON-serialization in general Serialize complex datatypes Frictionless Persistence in.net 21

Let s see... DEMO Connect with mongo-csharp Insert, query, update, query Insert complex model Frictionless Persistence in.net 22

Now let s take a look at a TINY WEB APP SAMPLE Frictionless Persistence in.net 23

Purpose Collect questions from audience during presentations Allow audience to vote Should be easy to find the session you re at Frictionless Persistence in.net 24

Required functionality Session has title, location, duration and questions Question has text and votes Create new session Add question to session Only if question does not already exist Increment votes on question Only if person has not voted on that question before Search for ongoing sessions near current location Show all ongoing sessions Be fairly accessible from both desktop & mobile Frictionless Persistence in.net 25

PriorityQ Frictionless Persistence in.net 26

PriorityQ Frictionless Persistence in.net 27

PriorityQ Frictionless Persistence in.net 28

The model (roughly) Session Headline Duration 0...1 Location Lat Lng * Question Text Votes Voters Frictionless Persistence in.net 29

Questions within a session Session is at the document level, and among other things it has an array of questions { } // (...) Questions: [ {Text: blah blah?, Votes: 0}, ] Frictionless Persistence in.net 30

Add question to session C#: var sessions = database.getcollection<session>( Session ); var text = blah? ; var criteria = Query.And(Query.EQ( _id, id), Query.NE( Questions.Text, text)); var update = Update.AddToSet( Questions, new Question {Text = text}); sessions.update(criteria, update); { // (...) Questions: [ {Text: blah blah?, Votes: 0}, {Text: blah?, Votes: 0} ] } Frictionless Persistence in.net 31

Increment votes on question C#: var sessions = database.getcollection<session>( Session ); var criteria = Query.And(Query.EQ( _id, id), Query.NE( Questions.1.Voters, joe )); var update = Update.Inc( Questions.1.Votes, 1).Push( Questions.1.Voters, joe ), sessions.update(criteria, update); { // (...) Questions: [ {Text: blah blah?, Votes: 0}, {Text: blah?, Votes: 1, Voters: [ joe ]}, ] } Frictionless Persistence in.net 32

Location within session Each Session can have a location object containing latitude and longitude coordinates { // (...) Location: { Lat: -40.232556, Lng: -45.2535353 } } Frictionless Persistence in.net 33

Create geospatial index Geospatial index can be added to any object containing exactly two floating point values (at most one geospatial index per collection though) C#: var sessions = database.getcollection<session>( Session ); sessions.createindex(indexkeys.geospatial( Location )); Mongo shell: use PriorityQ db.session.ensureindex({location: 2d }) Frictionless Persistence in.net 34

Query geospatial index C#: var sessions = database.getcollection<session>( Session ); var query = Query.Near( Location, lat, lng, maxdistance); sessions.find(query); Frictionless Persistence in.net 35

Conclusion Was very easy to Get started persisting some data Satisfy invariants Extend the model with geospatial capabilities Look at and modify data while developing Run tests on local MongoDB Deploy app to AppHarbor using MongoHQ for hosting my MongoDB instance Frictionless Persistence in.net 36

By now, it s obvious that MongoDB is pretty cool and easy to get started with, and it has a pretty sweet spot in backends for e.g. mobile, possibly location-aware apps... but how about SOME (GRANDER) USAGE SCENARIOS Frictionless Persistence in.net 37

CQRS Event store Persist batches of events in one document (NServiceBus-committer Jonathan Oliver has MongoDB support in his EventStore project: https://github.com/joliver/eventstore) Query store Quick to add new views Take advantage of ad-hoc querying Frictionless Persistence in.net 38

Caching Example on implementing a distributed cache by Peter Bromberg: http://www.eggheadcafe.com/tutorials/aspnet/93206c89-09c9-40fc-9296-7d74bb7996ad/a-mongodb-cache-utility.aspx Frictionless Persistence in.net 39

Central logging database There s a Log4net appender for MongoDB: Log4Mongo: https://github.com/log4mongo/log4mon go-net (just punch in a few lines of XML, and then you re good to go.) Frictionless Persistence in.net 40

Storing aggregate roots Document == DDD aggregate root Objects beneath the root live & die with the root A root represents a transactional boundary (no more how do I load an entire aggregate root in one query with NHibernate?).. Frictionless Persistence in.net 41

Sour spots Heavily interrelated stuff Like e.g. social network relations Relational and transactional stuff Some data IS in fact relational in nature and should be transactional across tables/rows ( and there s probably many other sour spots ) Frictionless Persistence in.net 42

A quick mention of some someones WHO S USING IT Frictionless Persistence in.net 43

Who uses it? Great blog on how Boxed Ice use MongoDB as the backend of their server monitoring application, Server Density: http://blog.boxedice.com/ Frictionless Persistence in.net 44

Who uses it? Nice presentation about why The Guardian chose MongoDB over CouchDB and other NoSQL type dbs: http://www.slideshare.net/tackers/why-wechose-mongodb-for-guardiancouk Frictionless Persistence in.net 45

Who uses it? Nice blog post on how Attachments.me followed 10Gen s guidance and tuned their MongoDB performance: http://attachmentsme.tumblr.com/post/516 8114317/tips-from-a-production-mongodbdeployment Frictionless Persistence in.net 46

Who uses it? Short interview on why MTV Networks s CMS is based on MongoDB: http://blog.mongodb.org/pos t/5360007734/mongodbpowering-mtvs-web-properties Frictionless Persistence in.net 47

Who uses it? Presentation by FourSquare on why they moved from Postgres to Mongo: https://docs.google.com/present/view?id=dh kkqm6q_13gm6jq5fv&pli=1 Frictionless Persistence in.net 48

Litterature MongoDB The Definitive Guide by Kristina Chodorow and Mike Dirolf from 10Gen Frictionless Persistence in.net 49

Some cool resources http://www.mongodb.org Binaries, official drivers, great documentation http://mongly.com The Little MongoDB Book Interactive MongoDB tutorials in the browser! http://www.snailinaturtleneck.com/blog/ Kritstina Chodorow s blog Frictionless Persistence in.net 50

Some cool resources http://www.mongohq.com Hosted MongoDB free for instances with less than 16 MB of data! http://www.mongovue.com Management GUI (written in C#... completely free until recently, now it s $35 still free evaluation though) Frictionless Persistence in.net 51

What s in the queue? Frictionless Persistence in.net 52

Remember this... It is not the strongest of the species that survives, nor the most intelligent that survives. It is the one that is the most adaptable to change. - Charles Darwin Frictionless Persistence in.net 53

Thank you for listening! Mogens Heller Grabe twitter://mookid8000 mhg@trifork.com http://mookid.dk/oncode You can leave personal feedback here: http://speakerrate.com/talks/7415 Frictionless Persistence in.net 54

Some image credits 1. I speak JavaScript : http://www.cafepress.com/+i_speak_javascript_mug,55296885 2. Bison: http://toyandgift.co.uk/acatalog/14349%20american%20bison.jpg 3. Snowflakes: http://italiano.istockphoto.com/stock-illustration-4195149-snowflakes-worn.php 4. Darwin: http://lmgtfy.com/?q=darwin 5. Enterprise: http://www.flickr.com/photos/sgodt/3279515658/ 6. Lemon: http://www.flickr.com/photos/darwinbell/258156642/ I m very grateful I could use your photos if you ever meet me, I ll buy you a beer (or another cold beverage of your choice ) Frictionless Persistence in.net 55