GomalId
GomalId

Reputation: 77

Saga pattern to delete Client data and associated resources

I'm working on a system that allows associating attachments to different business entities, such as to a Client. To simplify things, the system has the following database tables:

I need to create a process to completely delete a Client entity and any information associated with it. This can certainly be achieved with a Saga pattern but I'm struggling to determine -from a design perspective- what information I may need to support this pattern.

For instance:

The saga would go like this:

  1. Delete files from filesystem.
  2. Delete records from the ClientAttachment table.
  3. Delete record from the Client table.

Now, I need a way to prevent further attachments from being uploaded while the operation is in progress, so I'm thinking I'll have to add a ClientState (OK, Deleting, Deleted, etc.) field to the Client table to validate this.

Is this the correct way of doing this kind of things? Is there any better way of doing this?

Upvotes: 0

Views: 49

Answers (1)

Rob Conklin
Rob Conklin

Reputation: 9479

You can also explore whether your database supports exclusive row-locks, which is what you are effectively trying to accomplish with your ClientState. Also, while looking at transactions, put your file operations last. That way if something fails you can roll back database transactions and not leave things in quite as dirty of state.

Upvotes: 0

Related Questions