What are some proven patterns for implementing soft-deletable resources in a service oriented architecture?

StackOverflow https://stackoverflow.com/questions/22169680

  •  02-06-2023
  •  | 
  •  

Question

We have a legacy monolithic Ruby on Rails application and we want to refactor it creating a group of web services. So the Users resource and the Cars resources will be handled in two different web applications.

But we have a very important feature: Soft-deletes. Soft-delete means that you can remove a user but then you can recover it. Implementing this soft-delete is straightforward for the simplest case: You delete a user, you undelete it – the User service knows all about of it.

But it gets complicated when the resource that you are deleting have some relation to other resources that are handled in a different service. In the example of the user, we think that the user has cars. When you delete a user, you delete his cars. When you undelete the user, the services should restore his cars too.

Some possibilities we have thought:

  • When a User is removed, hardcode a web request to the service that removes his Cars.
  • Implement an event system: So that you delete a resource, the service that did it will raise a 'deleted' event and send it to all registered services for that event.

Has anybody had good or bad experiences following any of the previous patterns? What are some other good options for implementing this feature?

Was it helpful?

Solution

The event implementation usually works quite nicely. However since the services are dispersed you may want to add some mechanism to make sure deletes (and undeletes) are handles by all the relevant services. The two common ways to achieve this are orchestration (i.e. an external coordinator that makes sure all the actions are carried) or by a Saga (a long running interaction with some coordination between involved services)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top