spring-bootrabbitmqmicroservices

How to share files between two microservice in both cloud and on-prem setups?


In my existing monolith application, I generate files that need to be sent as email attachments. I've started moving to a microservices architecture, where an event is raised via RabbitMQ to trigger email sending in a different microservice.

The challenge is: I need to send the file generated by Monolith as an attachment in the email from the new microservice.

I know that using an S3 bucket (or similar object storage) would be a good approach in a cloud environment—upload the file, pass the reference via the event, and download it in the email service. However, I also need to support an on-premises deployment, where I can't rely on services like S3 or introduce additional infrastructure that clients must maintain.

What is the best way to handle this scenario in both cloud and on-prem environments?

What would you recommend for this kind of hybrid setup?


Solution

  • You're right - in the cloud, the solution is to upload the file to object storage (like S3, MinIO, or Azure Blob Storage), then send a reference (URL or ID) to the email service via your RabbitMQ event.

    But for on-premises setups where external infrastructure like S3 isn't available or desirable, you can use a hybrid approach:

    In the cloud:

    On-prem:

    The email service is subscribed to the RabbitMQ queue, receives the event, and loads the file either from object storage (in the cloud) or from the local filesystem (on-prem) before sending it as an email attachment.