Search code examples
c#.netazureazureservicebusservicebus

.NET - How share data between service and azure function


I have a problem regarding data sharing between services. I have Service1, where I have a configuration stored, which is set on the frontend in the database - archiving time, etc. Next to that I have Service2 (which is a couple of azure functions) which has its own database. Once a day I would need to delete old data in Service2 using the time function. However, in this time function I need the configuration from service1. To be honest I don't know exactly how to approach this. Service1 holds this configuration because it is a miscellaneous configuration and not just a configuration to delete archive data.

  • I was thinking of keeping the configuration in Service1 and in case of modification via Service bus, notifying Service2 who will save it. However, this is where the common problem of data being stored in both places arises.

  • Keeping this only in Service2, where I now override it via Service1 (service bus), but in the future it could for example be called via the api gateway? However, here's the problem again, if I need to display this data on a frontend that looks into service1, I don't know exactly how to do that.

  • In service1 store the data in a table and for example table storage and then take it from service2. But again, there is duplication of data.


Solution

  • If two services need to share configuration, it could be accomplished in several ways. The two scenarios you could try would be:

    1. One service can read and modify the settings. When settings are modified, it announces (publishes an event) to communicate the change. That's assuming the second service doesn't have direct access to the persistence.
    2. Allow both services to read the settings, but only one of the services can write.

    I'd try to pursue the first path because it's more scalable and less prone to issues of who's in charge of the data. It also removes the need to keep all services aware of the credentials. And, services can scale out, be added, and still get notified about the settings change.