Earlier I wrote a blog post about the general concept of microservices vs a monolithic structure for projects. In this post I’m going to go into more detail about the specific microservice I will be developing for our project that encompasses the database interactions. This microservice will be responsible for taking in incoming requests from one of the other microservices and translating it to a query to be executed on the database server and then return the correct data. I’m going to go over the basic components needed to create a microservice involving databases.
When creating any sort of backend that involves interacting with a database there a few main things that must be taken into consideration, the database itself, the database server, and how to send queries to the database. For this project we’re using a PostgreSQL database hosted on a Heroku server that we will be interacting with via node.js utilizing PostgreSQL specific libraries and an object-relational mapper. I will go into further detail on this topics in the next sections and how they relate to my groups project.
The first choice you have to make when thinking about creating a database microservice is what type of database you want to use. There are a ton of database services out there with different pros and cons that make certain ones better in some situations than others and it can be daunting to chose. The one database that we decided to use is a PostgreSQL database because it is opensource and it has been around for a long time so there are a lot of libraries built for it and other tools that help integrate it into projects. Speaking of tools that help integrate PostgreSQL into your projects that brings us to the next topic, database server.
In order to have any sort of app or website interact with your database it has to be hosted somewhere which is where the database server come in. The database server is just a site that holds your database and maintains the entity relationships so that you can send queries to it and have your data returned. There are a lot of different services that provide this and a lot of them are not free to use because but for our project we are using a free service provided by Heroku. Heroku provides tools that allow you to create a database server that you can connect to if you have the credentials for that server and database and send queries to it and have data returned. Our database is hosted on this service and the integration has been pretty smooth when I have interacted with it from pgAdmin which is just a tool that can be used to create or connect to an existing database and interact with it via SQL queries.
So with these tools selected and outlined I’m now ready to start on the last major part of the project that I’m responsible for. This is a pretty huge part of our application so it’s going to take me a significant amount of time but luckily these tools are very well developed and documented. Maybe this post will be a good start for someone else looking to create a database microservice that is overwhelmed by all the different options nd combinations of tools out there.