Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
scroll top