polyglot persistence applications on openshiftnosql to the rescue • schema-less • rich documents...

36
Polyglot Persistence Applications on OpenShift By Shekhar Gulati Promo Code – JUDCON.IN

Upload: others

Post on 25-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Polyglot Persistence Applications on OpenShift

By Shekhar GulatiPromo Code – JUDCON.IN

Page 2: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

About Me ~ Shekhar Gulati

• OpenShift Evangelist at Red Hat• Hands on developer• Speaker• Writer and Blogger• Twitter @ shekhargulati

Page 3: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing
Page 4: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Now we have choices ... lots of them

http://nosql-database.org/ list 122+ databases

Page 5: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Why not RDBMS?

• Widely used and understood• Tested in real environments• Efficient use of storage space if data

normalized properly• Great tools support• ACID semantics• Incredibly flexible and powerful query

language• Great framework support

Page 6: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

RDBMS have limitations

• Complex object graphs does not map very well with flat tables.

• Difficult to evolve Schema with time.• Data constraints and JOINs can be

expensive at runtime.• Difficult to scale horizontally.

Page 7: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

NoSQL Databases to rescue

Page 8: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

NoSQL to the Rescue

• Schema-less• Rich documents• Eventual consistent• Fast writes• Easy to scale horizontally to add processing

power and storage• Tries to solve few practical use-cases

Page 9: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Polyglot Persistence

Using multiple data storage technologies, chosen based upon the way data is being used by individual applications or components of single application.

Martin Fowler

http://martinfowler.com/articles/nosql-intro.pdf

Page 10: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Polyglot Persistence – Hypothetical Example

http://martinfowler.com/articles/nosql-intro.pdf

Page 11: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Get more information at ...

Page 12: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Application Use case : Location Aware Job Search Portal

Page 13: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

User Stories

● As a User, I should be able to find all the jobs.

● As a User, I should be able to find all the jobs near to my location.

● As a User, I should be able to find all MongoDB (or any skill) jobs near to my location.

● As a User, I should be able to find all the MongoDB (or any other skill) jobs near to my location with distance.

Page 14: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Technology Choices

• OpenShift• MongoDB• PostgreSQL• Java

– Spring Framework– Spring Data MongoDB– Spring Social

• Git• Twitter Bootstrap

Page 15: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

What is MongoDB?

• Document Oriented database– JSON-style documents: Lists, Maps, primitives

• Schema-less– Each document is heterogeneous, and may have

completely unique structure compared to other documents.

• Fast and horizontally scalable• Rich query language

Page 16: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

MongoDB Terminology

Database → Database

Table → Collection

Row → Document

Index → Index

Page 17: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Why MongoDB?

• Easy to get running • Open Source• Active community• Rich documents• Geospatial indexing.• Writes are very fast. You can customize it

using WriteConcern.

Page 18: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Rich Document

Page 19: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Geospatial Indexing Basics• What is it for?

– Find all the MongoDB jobs near me– Find all the MongoDB jobs within London

• Supports only two dimensional indexes.

• You can only have one geospatial index per collection.

• The spatial functionality MongoDB currently has is:– Near– Containment

http://www.mongodb.org/display/DOCS/Geospatial+Indexing

Page 20: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

How to make it work?

• Put your coordinates into an array{ loc : [ 50 , 30 ] } //SUGGESTED OPTION

{ loc : { x : 50 , y : 30 } }

{ loc : { foo : 50 , y : 30 } }

{ loc : { lon : 40.739037, lat: 73.992964 } }

• Make a 2d indexdb.places.ensureIndex( { loc : "2d" } )

Page 21: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

OpenShiftis

PaaS by Red Hat

Multi-language,Auto-Scaling,Self-service,

Elastic,Cloud Application Platform

Page 22: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Why choose PaaS?

Lowers Cost Improves Developer Efficiency

Scales

Page 23: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Why OpenShift?

• Supports MongoDB and PostgreSQL. Also supports MySQL.

• Multi-language support. Supports Java, Node.js, Perl, Python, PHP and Ruby.

• Extensible via DIY

• No need to learn anything new.• Open source – OpenShift Origin• Scalable. • FREE!

Page 24: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

How To Work with OpenShift

Developer IDEIntegrations

Web BrowserConsole

Command LineTooling

REST APIs

Page 25: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Getting Started with OpenShift

Sign up with Promo Code

JUDCON.IN

https://openshift.redhat.com/app/account/new

Page 26: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

What I get after sign up?

• OpenShift is free-as-in-beer & free-as-in-freedom

• You get three free gears, each with 512MB memory and 1GB of disk space.

• Need more resources, just ask!

• The catch is we are in developer preview right now

Page 27: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Install Client Tools and Setup Account

• Install the client tools • rhc setup -l <openshift_login>

Page 28: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Creating an OpenShift Application

rhc app create -a jobfinder -t jbossews-1.0

Page 29: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Adding MongoDB and PostgreSQL

rhc cartridge add -a jobfinder -c mongodb-2.2

rhc cartridge add -a jobfinder -c postgresql-8.4

Page 30: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Play with MongoDB running in the Cloud

● ssh into instance● Type mongo on the shell● Create a sample db● Insert some documents in the collection● Run some queries

Page 31: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Pulling code from github

git rm -rf src pom.xml

git commit -am “removed default files”

git remote add jobfinder -m master git://github.com/shekhargulati/jobfinder.git

git pull -s recursive -X theirs jobfinder master

Source code is on github

https://github.com/shekhargulati/jobfinder

Page 32: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Importing data into MongoDB

rhc app show -a jobfinder -l <openshift_login_email>

scp jobs-data.json <instance_ssh_access>:app-root/data

ssh <instance_ssh_access>

mongoimport -d jobfinder -c jobs --file jobs-data.json -u $OPENSHIFT_MONGODB_DB_USERNAME -p $OPENSHIFT_MONGODB_DB_PASSWORD -h $OPENSHIFT_MONGODB_DB_HOST -port $OPENSHIFT_MONGODB_DB_PORT

db.jobs.ensureIndex({"location":"2d"})

Page 33: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Show some geospatial queries

Page 34: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Deploy the application to OpenShift

git push

Page 35: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Next Steps For You

• Try out OpenShift• Deploy your first application on

OpenShift• Write a blog about your experience

Page 36: Polyglot Persistence Applications on OpenShiftNoSQL to the Rescue • Schema-less • Rich documents • Eventual consistent • Fast writes • Easy to scale horizontally to add processing

Conclusion• OpenShift is very easy to use and you can build

polyglot persistence applications on it.

• MongoDB makes it very easy to build location aware applications.

• All the Spring latest projects work without any problem on OpenShift.

• Did I mention – Free?

• What are you waiting for? Try it out.

• Sign up using JUDCON.IN promo code.