Recently I have been trying to learn a little bit about software architecture and one concept that pops up a lot is that each service should not reach beyond it’s own boundry and just be responsible for it’s own data. If something happens in one service that means another service has to do something then service A
should raise an event in a broker that service B
subscribes to. My understanding is that this keeps the services clean and easier to refactor if you have to scale an individual service.
What would be the ServiceStack way to approach this? It seems like it would be with SSE but I am unsure exactly on the implementation. Are there any real world examples?
Let’s says I have 3 http service endpoints:
/Payment
/Warehouse
/Notification
When a payment is received we need to create a work item in the warehouse and send out some notifications.
So I could create a message with the relevant data.
public class PaymentReceived
{
public string PaymentId { get; set; }
public string[] WarehouseItems { get; set; }
public string[] Emails { get; set; }
}
And then in the /Payment
endpoint send that message to a channel
ServerEvents.NotifyChannel("payment-received", paymentReceived);
But now I am a bit unsure of how the subscription works. /warehouse
and /notification
are scoped to a HTTP request so I need a background service that listens to the payment-received
channel and then generates calls to http endpoints and handles exceptions/retries. I am not sure how best to structure this in the project or if I am totally off base here and there is a better/easier way to handle service boundaries in servicestack. I am just trying to have some sort of broker in-between services.
What do you recommend for this scenario?