1

I have a php web application that is written with traditional architecture with templating, controllers and ORM models.

I also have a nodejs JSON API web service that accepts incoming connections and responds with JSON responses

Both Services operate on the same database and provide similar functionality but they differ in the response type and different routes.

This introduces problems with keeping both services updated to the latest business requirements and discrepancies that occur between the services.

My question is what are my best options to keep both services in sync?

  • 1
    write a .Net data access layer and get both to call it – Ewan May 22 '17 at 11:40
  • @BackendDeveloper92 by to keep both services in sync. What do you mean? To keep synchronised the data or the code base? – Laiv May 22 '17 at 12:06
  • mainly the code base including business rules and database schema – Backend Developer 92 May 22 '17 at 12:24
  • provide similar functionality. How similar are they? Would you dare to say that both represents the same business? – Laiv May 22 '17 at 17:54
  • yes they both repesent the same business – Backend Developer 92 May 23 '17 at 11:42
1

My question is what are my best options to keep both services in sync?

»Help doctor, I poke with this skrewdriver in my eyes and it hurts a lot! How can I continue in such a way, that it hurts less?«

I would recommend, stop doing, what you are doing! Immediately!

Clearly: This setup smells like trouble and pain.

Both Services operate on the same database and provide similar functionality but they differ in the response type and different routes.

1- the API was written in NodeJs becuase there were plans to migrate from PHP. 2- the code base is medium-large 3- re-writing in PHP is possible but it is alot of work.

This is wrong for many reasons.

But what wonders me is, that you aren't doing the obvious:

  • Define one service with one API as the truth and retire the other

Even if your rewrite costs you some sweat and tears, think of the sweat and tears you are not going spent later, dealing with a mess. There is no easy way, but everything will be easier than to deal with a broken setup.

Unfortunately, you are not telling us more details, so the advice is a general one.

  • 1
    I like this answer. I didn't dare to say it but you are right, someone made a couple of wrong decisions. First duplicating the business and second do it with different tech stack. – Laiv Jul 21 '17 at 18:36
  • And funniest thing: this Question is labeled »microservice« I wonder where the micro-side of things is hiding – Thomas Junk Jul 22 '17 at 0:05
0

Create a single data access service that exposes the needed objects and have both projects call to this service for database access. The trick to doing this is to not just copy all your data access methods from each project and add them to a data service, because then you just added more overhead and complexity for no gain. where your existing data access exists would now essentially become a data transformation layer that gets data from more general services and shapes it the way that app needs.

The idea is to create a single access point that responds with what you need in a way that it can either be used directly or with minimal modification from consuming apps. The only way to really ensure your apps are in sync is to ensure they call the same code, and even then you still need the discipline to not add logic to each app separately that shouldn't belong there. This is a major change to implement, but it's much easier if your existing apps are properly isolating their own data access already.

  • do you mean isolating data access into a third service. what about other operations like data validation or access control ? – Backend Developer 92 May 22 '17 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.