thinking beyond rdbms - building polyglot persistence java applications devfest vienna

35
OPENSHIFT Workshop PRESENTED BY Shekhar Gulati Thinking Beyond RDBMS : Building Polyglot Persistence Java Applications

Upload: shekhar-gulati

Post on 11-May-2015

646 views

Category:

Technology


3 download

DESCRIPTION

Thinking beyond RDBMS - Building Polyglot Persistence Java Applications Devfest Vienna

TRANSCRIPT

Page 1: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

OPENSHIFTWorkshop

PRESENTEDBY

ShekharGulati

Thinking Beyond RDBMS : Building Polyglot Persistence Java

Applications

Page 2: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

WHO AM I?

• Shekhar Gulati -- OpenShift Developer Evangelist

• Java / JavaScript /Python / NoSQL / Cloud Guy

• Twitter Handle : shekhargulati

• Github https://github.com/shekhargulati

• Slides http://www.slideshare.net/shekhargulati

Page 3: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

AGENDA

Page 4: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

WHO ARE YOU?

Page 5: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

There are no stupid questions only stupid answers. So ask questions

ASK QUESTIONS

Page 6: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

http://nosql-database.org/ lists 150 databases

NOW WE HAVE CHOICES ...

Page 7: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

● 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

WHY RDBMS?

Page 8: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

● 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.

RDBMS LIMITATIONS

Page 9: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

NoSQL Databases to rescue

Page 10: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

● Schema-less

● Eventual consistent

● Scales writes and reads

● Easy to scale horizontally to add processing power and storage

● Tries to solve few practical use-cases

NoSQL TO RESCUE

Page 11: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

NoSQL CLASSIFICATIONCLASSIFICATION

Source http://www.slideshare.net/bscofield/nosql-codemash-2010

Page 12: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

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

POLYGLOT PERSISTENCE

Page 13: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

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

HYPOTHETICAL EXAMPLE

Page 14: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

GET MORE INFO AT

Page 15: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

APPLICATION

http://localjobs-t20.rhcloud.com/

Page 16: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

● MongoDB – Storing Jobs data

● PostgreSQL – Storing Users data

● Redis – Cache for Users

● Java 7

– Spring framework , Spring Social, Spring MongoDB, Spring Security , Spring Redis , etc.

● OpenShift

● Git

● Twitter Bootstrap

● jQuery

● Searchify : Full-text Search as a Service

TECHNOLOGY CHOICES

Page 17: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

● Document Oriented database

– JSON-style documents

● Schema-less

– Each document is heterogeneous, and may have completely unique structure compared to other documents.

● Fast and horizontally scalable

● Rich query language

MONGODB

Page 18: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

Database → Database

Table → Collection

Row → Document

Index → Index

MONGODB TERMINOLOGYMONGODB TERMINOLOGY

Page 19: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

● Easy to get running

● Open Source

● Active community

● Rich documents

● Geospatial indexing

● Writes are very fast. You can customize it using WriteConcern

WHY MONGODB?

Page 20: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

RICH DOCUMENT

Page 21: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

21

What is it for? Find all the MongoDB jobs near me – Proximity Queries Find all the MongoDB jobs within Colombo – Bounded

Queries Find all the MongoDB job at this location – Exact Queries

● Supports only two dimensional indexes. You can only have one geospatial index per collection. By default, 2d geospatial indexes assume longitude

and latitude have boundaries of -180 inclusive and 180 non-inclusive (i.e. [-180, 180))

GEOSPATIAL INDEXING BASICS

Page 22: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

22

1) Put your coordinates into an array

{ loc : [ 50 , 30 ] } //SUGGESTED OPTION

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

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

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

2) Make a 2d index

db.places.ensureIndex( { loc : "2d" } )

3) If you use latitude and longitude as your coordinate system, always store longitude first. MongoDB’s 2d spherical index operators only recognize [ longitude, latitude] ordering.

HOW TO MAKE IT WORK

Page 23: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

OpenShiftis

PaaS by Red Hat

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

Elastic,Cloud Application

Platform

Page 24: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

● Supports MongoDB , PostgreSQL ,and MySQL

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

● Extensible via DIY and cartridges

● No need to learn anything new

● Open source – OpenShift Origin

● Scalable

● FREE!

WHY OPENSHIFT?

Page 25: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

origin

Public Cloud Service

On-premise or Private Cloud Software

Open Source Project

FLAVORS OF OPENSHIFT

Page 26: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

26

OUR STACK

Page 27: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

27

Let's build the application

Page 28: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

28

OPENSHIFT – GETTING STARTED

●Go tohttps://openshift.redhat.com/app/account/new

Promo code is DEVFEST2013●Create namespace●Install rhc command line

utility●Run rhc setup command

Page 29: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

29

Lot of other tasks you can do with rhc – tail log, app management, cartridge management , ssh management , namespace management, etc. Run rhc -h for details

DEMO : LOCALJOBS APP

Page 30: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

HOW IT FITS

Page 31: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

31

$ git rm -rf src pom.xml

$ git commit -am “delete template app”

$ git remote add upstream -m master https://github.com/shekhargulati/localjobs-demo.git

$ git pull -s recursive -X theirs upstream master

ITS All GIT

Source code https://github.com/shekhargulati/localjobs-demo

Page 32: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

32

git push

Page 33: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

33

Code Walkthrough

Page 34: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

QUESTIONS?

Page 35: Thinking beyond RDBMS  - Building Polyglot Persistence Java Applications Devfest Vienna

DONE!