Design a site like this with WordPress.com
Get started

Creating a database agnostic backend

TLDR: How do we refactor our backend code so that we can easily swap between databases without changing too much code.

We have an Express Firebase backend. We use the firebase-admin library which allows you to use firebase in a server environment. We want to start supporting multiple databases so that we can swap them as the need arises. We currently have Firestore (firebase database) function calls throughout our routes but we want to abstract database interactions so that our routes don’t have to change much or at all when we change databases.

The problem is that the structure of the databases differs between providers. For instance, Firestore has the concept of subcollections which some other databases don’t have. They also handle ordering and limiting reads in their own specific ways with their own specific apis. MongoDB, DynamoDB etc may handle all this differently.

How can we architect our app so that we can reuse as much code as possible in a way that is relatively easy to maintain?

The solution I’m thinking about involves creating a generic datastore interface that contains common database operations that the specific databases can implement. But I’m not sure how I’m going to handle very niche use cases that don’t easily translate between databases and how I’m going to translate concepts that don’t exist in all databases such as subcollections for one example.

Is this a solved problem in industry and are there any resources that may point me in the right direction? Something like Clear Architecture or Hexagonal Architecture may be a bit overkill for us as we don't have the resources for such a big rewrite.

Thanks

submitted by /u/dazzaondmic
[link] [comments]

from Software Development – methodologies, techniques, and tools. Covering Agile, RUP, Waterfall + more! https://ift.tt/7kSCQDB

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close