Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple databases within the same application

I am currently developing an application in node.js. I have a Postgres/PostGIS database to store geospatial information and render them as SVG. That works fine so far. On the other side I have a CouchDB database filled with data, from a previous project.

I'd like to combine this data with the geospatial data from postgis via node.js, but I am not sure on how to proceed with the structure of my databases.

Is it a good idea to work with two different database types - even paradigms - in one application? Or is is better to transform the data from one db to the other?

BTW: This is purely a hobby project.

like image 419
Mathias Vonende Avatar asked Apr 28 '13 08:04

Mathias Vonende


People also ask

Can we use multiple databases for a single application?

If you can work with single database, working with multiple is no different. You will need a connection string for each database. There rest is, as they say it, history.

Can an application have two databases?

Multiple database technologies can be used with monolithic applications, and can even seem more natural in a microservices environment, where each service would have its own database.

Can we have two databases configured for the same application?

To connect multiple databases, each database should be configured in its own spring boot configuration file. Multiple data sources should be configured for multiple databases. For spring data classes and spring data JPA repositories, two separate java packages need be created.

How many databases can one application contain?

You can, I believe, create more than 256 databases per instance, but only 256 can be active at any point. If you try to activate more databases than you have configured for numdb, you will get: SQL1041N The maximum number of concurrent databases have already been started.


1 Answers

There's nothing wrong with accessing two databases from one application. It's a model used frequently. It's not uncommon to have a Node server access both Mongodb and Redis, using each for their strengths. You just have to tie data relations together in your app instead of in the database.

Node is particularly suited for multi-database applications because you can access multiple resources simultaneously. The async package makes it easy to query multiple databases at the same time and merge the results. This is something that synchronous servers typically do in order, waiting for one result before sending off the query for the second result. So if you take full advantage of Node's capabilities, you'll have a better experience accessing multiple data sources then you would from many other popular web development platforms.

like image 126
Daniel Avatar answered Oct 04 '22 20:10

Daniel