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

Foss.in Talk on Building Polyglot Persistence A...

Foss.in Talk on Building Polyglot Persistence Application using OpenShift

Foss.in Talk on Building Polyglot Persistence Application using OpenShift

Shekhar Gulati

November 29, 2012
Tweet

More Decks by Shekhar Gulati

Other Decks in Programming

Transcript

  1. 11/29/12 Polyglot Persistent Spring Applications in the Cloud Shekhar Gulati

    OpenShift Evangelist, Red Hat 29th November 2012
  2. Shekhar Gulati 2 About Me ~ Shekhar Gulati • OpenShift

    Evangelist at Red Hat. • I write code. • Active blogger http://whyjava.wordpress.com/ and https://openshift.redhat.com/community/blogs • Written many technical on IBM DeveloperWorks, Developer.com, JavaLobby. • Active speaker ~ Red Hat Developer Day, JUDCon, JBoss World, SiliconIndia events,etc. • Passionate to learn new things. • Twitter : shekhargulati
  3. Shekhar Gulati 5 Now we have choices ... lots of

    them http://nosql-database.org/ list 122+ databases
  4. Shekhar Gulati 6 Why should I care when RDBMS has

    served us very well? • 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
  5. Shekhar Gulati 7 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.
  6. Shekhar Gulati 9 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
  7. Shekhar Gulati 10 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
  8. Shekhar Gulati 14 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.
  9. Shekhar Gulati 15 Technology Choices • OpenShift • MongoDB •

    PostgreSQL • Java • Spring Framework • Spring Data MongoDB • Spring Social • Git • Twitter Bootstrap
  10. Shekhar Gulati 16 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
  11. Shekhar Gulati 17 MongoDB Terminology Database → Database Table →

    Collection Row → Document Index → Index
  12. Shekhar Gulati 18 Why MongoDB? • Easy to get running

    • Open Source • Active community • Rich documents • Geospatial indexing. • Writes are very fast. You can customize it using WriteConcern.
  13. Shekhar Gulati 20 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
  14. Shekhar Gulati 21 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" } )
  15. Shekhar Gulati 22 OpenShift is PaaS by Red Hat Multi-language,

    Auto-Scaling, Self-service, Elastic, Cloud Application Platform
  16. Shekhar Gulati 24 Why OpenShift? • Supports MongoDB and PostgreSQL.

    Also supports MySQL. • Multi-language support. Supports Java, Node.js, Perl, Python, PHP and Ruby. • Extensible vi DIY • No need to learn anything new. • Open source – OpenShift Origin • Scalable. • FREE!
  17. Shekhar Gulati 25 Developers Choose How To Work with OpenShift

    Developer IDE Integrations Web Browser Console Command Line Tooling REST APIs
  18. Shekhar Gulati 27 What do I get? • 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
  19. Shekhar Gulati 31 Adding MongoDB and PostgreSQL support rhc cartridge

    add -a jobfinder -c mongodb-2.2 rhc cartridge add -a jobfinder -c postgresql-8.4
  20. Shekhar Gulati 32 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
  21. Shekhar Gulati 33 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
  22. Shekhar Gulati 34 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"})
  23. Shekhar Gulati 37 Next Steps For You • Try out

    OpenShift • Deploy your first application on OpenShift • Write a blog about your experience
  24. Shekhar Gulati 38 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 foss.in promo code.