0

We have a microservice that integrates with a third party system via REST API to handle appointment booking for our customer. It takes advantage of the event-driven model. Our microservice emits out an integration event called the AppointmentCreated event post-appointment booking with the third party service.

The AppointmentCreated event is handled in the processor, which notifies our internal(monolithic) system to do some POST appointment work. Example processes we have in processor and the processor will go to the next step regardless these steps succeed or not, which was okay when we started this project

  1. Notify the internal system that a customer booked an appointment
  2. Update User consents based on whether they selected to be opt-in for SMS notification

Current AppointmentCreated C#

public class AppointmentCreated : IntegrationEvent
{
        public int Id { get; set; }
        public DateTimeOffset CreatedAt { get; set; }
        public string PatientName { get; set; }
        public DateTimeOffset StartTime { get; set; }
        public DateTimeOffset EndTime { get; set; }
        public bool SmsConsent { get; set; }
        public Guid? ContactKey { get; set; }
        public string PatientEmail { get; set; }
}

Now the business is asking to notify the SalesForce team via a REST API call once the appointment is booked in our microservice with what we send out in the REQUEST with the third party and the RESPONSE we get from the third party HTTP call. The business also wants to be notified whether we fail to notify SalesForce for any number of reason, which we can have some alerts set up on the event bus to do that.

Would it make sense to emit out a specific integration event from our microservice just to notify ThirdParty on our event bus and handle the REST API to notify SalesForce in the processor? Emit two events after our microservice is able to book an appointment with the third party.

  1. AppointmentCreated
  2. NotifySalesForceAppointmentCreated only needs Request and Response data that we make the call to the third-party application to make an appointment. We only want this data on successful appointment booking. It doesn't care about the current AppointmentCreated content.

enter image description here

Do you guys have any suggestion or anything with this approach?

1 Answer 1

0

In my opinion there is only one event and it is AppointmentCreated.

On this event you can have different consumers(subscribers). One of this consumers can be dedicated consumer that has one job to notifying Sales Force.

The second event you have written NotifySalesForceAppointmentCreated is a command, not an event and in my opinion you don't need it.

Each consumer can hold separately execution / processing and decide if the consumer has reacted adequately on the event.

F.ex. Your NotifySalesForceAppointment in order to perform the notification to Sales Force needs to collect some data from external system via REST call.

  1. You consumer reacts on the event, the processing starts you write it to some persistent storage.
  2. You collect data from external systen via rest call, you write the data. (writing data is optional if things go wrong you can aways just go from the start)
  3. You notify the SalesForce and write into the persistent store that the processing is complete.

If one of these steps fail you can begin from the start.

11
  • Thank you for taking the time out for responding. I do agree with you on there is only one event. The NotifySalesForceAppointmentCreated definitely sounds more like a command than an event for sure. The reason why I wouldn't want to just have one event is that SalesForce requires specific information which is not useful for the current consumer. I wouldn't be sending information on my event bus for a consumer who doesn't care about the information that SalesForce cares about and vice versa. Commented Feb 26, 2021 at 19:28
  • 1
    As I said you can have different consumers. Now you need to separate your execution state and processing state from your event. The event is one, it is AppointmentCreated. The state you point out is execution/processing state of one consumer. You sould not mix your state with your event. Commented Feb 26, 2021 at 19:35
  • 2
    I think what Alexander means is that you create a new event handler that is a second consumer of the AppointmentCreated event; the single responsibility of this event handler is to make a request to the SalesForce REST Api with only the data required for that call. If this REST call fails, you can handle that error with some notification.
    – Rik D
    Commented Feb 26, 2021 at 19:40
  • Yes, I understand the approach of having two handlers to perform two district operations. I thought about this approach. What I really don't like is that I am having to modify the AppointmentCreated event to include the REQUEST and RESPONSE data that is needed to notify SalesForce. It may not be a big deal I guess to modify the existing event to include more data. Commented Feb 26, 2021 at 19:46
  • You don't need to modify the event. And you should not modify the event. Separate Event from execution/processing logic. These are two different things. Commented Feb 26, 2021 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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