Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Hybrid Persistence

DZone's Guide to

Hybrid Persistence

· Database Zone
Free Resource

MongoDB Atlas is a database as a service that makes it easy to deploy, manage, and scale MongoDB. So you can focus on innovation, not operations. Brought to you in partnership with MongoDB.

Often times the business requirements demand for database features that aren’t easily achievable using a single type of database. And now we have quite a few options to choose from, for example Key Value stores, Document databases, Relational databases etc, each providing some mutually exclusive features from the rest. So, it can be tempting to introduce multiple databases to rip the benefits of each.

But, it comes with a few gotchas that are worth knowing. Here’s a short list from my recent experience on a project:

  1. No simple way to join data from multiple databases without multiple round trips.
  2. Deployment is tricky as it adds more infrastructure.
  3. If data is duplicated, migrations need to address multiple sources.

Let’s explain this with an example. Say, we need to store data for an e-commerce site. Document stores seem to be good candidate for storing the product info, since different products have different data associated with it.

  {
    id: '4wqrqw4890ipoip',
    name: 'iPhone 5',
    color: 'Black',
    price: '699.99'
  }


  {
    id: '4wqrqw4890ipoiq',
    name: 'Fine Sheet',
    thread_count: 400,
    size: 'Queen',
    price: '699.99'
  }

We also need to store transactional data and Relational databases have been successfully used for transactions. So, a simple schema may look like this:

  Sales(id, store_id, product_id, quantity)

With a hybrid persistence approach like this, just beware that implementing simple features as follows will need more roundtrips:

  1. Show the invoice for sale with product name, quantity and price.
  2. Show all ‘Fine Sheets’ that are sold in the ‘Brentwood’ store.
  3. List all products sold today, sorted by name.

Hybrid persistence works fine for caching. But whenever your data is split into multiple sources in way that you’d have to combine the parts from each, it’s not gonna be fun time. Just so you know.



MongoDB Atlas is the best way to run MongoDB on AWS — highly secure by default, highly available, and fully elastic. Get started free. Brought to you in partnership with MongoDB.

Topics:

Published at DZone with permission of S M Sohan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}