Search code examples
spring-bootneo4jmariadb

Maintaining integrity using Mariadb and neo4j together


I am trying to create a following function through Neo4j in Spring Boot and store the following number in Mariadb. Is integrity maintained? If integrity is not maintained, should only one of the two DBs be used?

Like Instagram, this is a service where users can post and follow people.


Solution

  • Personally, I would try to use only one DB. As you add components to your system, the likelihood of failures grow exponentially. Keeping disparate systems in sync is not a trivial task.

    There's not enough information in the question to make a completely informed decision. It does depend on the scale of your system and the value to the business of keeping the data consistent.

    The amount of effort you want to put into a solution depends on the value of the service you're providing. You could go full on and use an enterprise scale broker to orchestrate the consistency between your services. This would help with knowing if the data has been written to Maria successfully and retrying transactions if it didn't.

    You might want to create an event based service so that updates get queued and applied in order if the Maria service is lagging behind Neo4j. This would provide less resilience than a full blown broker, but is relatively easy to implement. You would have to write the code to manage the queue, but wouldn't have to remove messages until you know they have been successfully processed.

    At the other end, you might be building a personal or small scale service for team or departmental use in which case a full blown broker architecture or queuing service will probably be completely over the top for the business value of the service. At this level (which sounds like the level you are at) you could write your own, mini broker which adds a property or label to a Neo4j node, tries the Maria transaction, then removes the property/label on success. You can then have some sort of clean up function which periodically scans the Neo4j database for stale property/labels.

    A final thought (and I've not really thought this one through very much) would be to write a Neo4j user defined function called to do the update. You could then bring your Maria update inside a Neo4j transaction. Be aware that this is going to have a performance impact on your Neo4j service especially if the Maria service is on a different node or network.