Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JUDCon India 2013 Polyglot Persistence Applicat...

Shekhar Gulati
January 18, 2013
100

JUDCon India 2013 Polyglot Persistence Application OpenShift

JUDCon India 2013 Polyglot Persistence Application OpenShift

Shekhar Gulati

January 18, 2013
Tweet

Transcript

  1. About Me ~ Shekhar Gulati • OpenShift Evangelist at Red

    Hat • Hands on developer • Speaker • Writer and Blogger • Twitter @ shekhargulati
  2. 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
  3. 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.
  4. 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
  5. 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
  6. 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.
  7. Technology Choices • OpenShift • MongoDB • PostgreSQL • Java

    – Spring Framework – Spring Data MongoDB – Spring Social • Git • Twitter Bootstrap
  8. 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
  9. Why MongoDB? • Easy to get running • Open Source

    • Active community • Rich documents • Geospatial indexing. • Writes are very fast. You can customize it using WriteConcern.
  10. 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
  11. 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" } )
  12. 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!
  13. Getting Started with OpenShift Sign up with Promo Code JUDCON.IN

    https://openshift.redhat.com/app/account/new
  14. 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
  15. Install Client Tools and Setup Account • Install the client

    tools • rhc setup -l <openshift_login>
  16. Adding MongoDB and PostgreSQL rhc cartridge add -a jobfinder -c

    mongodb-2.2 rhc cartridge add -a jobfinder -c postgresql-8.4
  17. 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
  18. 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
  19. 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"})
  20. Next Steps For You • Try out OpenShift • Deploy

    your first application on OpenShift • Write a blog about your experience
  21. 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.