Share
Embed
JUDCon India 2013 Polyglot Persistence Application OpenShift
JUDCon India 2013 Polyglot Persistence Application OpenShift
Shekhar Gulati
January 18, 2013
Transcript
36 slides
-
About Me ~ Shekhar Gulati • OpenShift Evangelist at Red
Hat • Hands on developer • Speaker • Writer and Blogger • Twitter @ shekhargulati -
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 -
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. -
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 -
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 -
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. -
Technology Choices • OpenShift • MongoDB • PostgreSQL • Java
– Spring Framework – Spring Data MongoDB – Spring Social • Git • Twitter Bootstrap -
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 -
MongoDB Terminology Database → Database Table → Collection Row →
Document Index → Index -
Why MongoDB? • Easy to get running • Open Source
• Active community • Rich documents • Geospatial indexing. • Writes are very fast. You can customize it using WriteConcern. -
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 -
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 index db.places.ensureIndex( { loc : "2d" } ) -
OpenShift is PaaS by Red Hat Multi-language, Auto-Scaling, Self-service, Elastic,
Cloud Application Platform -
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! -
How To Work with OpenShift Developer IDE Integrations Web Browser
Console Command Line Tooling REST APIs -
Getting Started with OpenShift Sign up with Promo Code JUDCON.IN
https://openshift.redhat.com/app/account/new -
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 -
Install Client Tools and Setup Account • Install the client
tools • rhc setup -l <openshift_login> -
Adding MongoDB and PostgreSQL rhc cartridge add -a jobfinder -c
mongodb-2.2 rhc cartridge add -a jobfinder -c postgresql-8.4 -
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 -
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 -
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"}) -
Next Steps For You • Try out OpenShift • Deploy
your first application on OpenShift • Write a blog about your experience -
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.