DEV Community

Cover image for Using Pub/Sub for event-driven Go backends

Using Pub/Sub for event-driven Go backends

Marcus Kohlberg on February 16, 2024

Pub/Sub is a powerful building block in a backend application. It's often used for building event-driven backend applications. Pub/Sub can be used...
Collapse
 
rod2j profile image
Rod Lecocq

What about the double write pattern problem here?
Does you Encore client take care of using sth like the outbox pattern? Because here if the message sending fails you will rollback your database tx and send an error to the user, but the message sending works but your db commit fails you get inconsistency

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Hey @rod2j - great point! There is indeed a package for implementing the outbox pattern. See the docs here: encore.dev/docs/primitives/pubsub/...

Collapse
 
olliekayden profile image
Olliekayden

Leveraging Pub/Sub in event-driven Go backends facilitates seamless tngofullform communication between services, promoting scalability and decoupling. With publishers broadcasting events and subscribers reacting accordingly, this approach fosters a more responsive and resilient architecture. Integrating Pub/Sub enables asynchronous processing, enhancing the efficiency and adaptability of the backend system.