oh $%!&, I didn't want to do that! UNDO UNDO UNDO!
You're writing an email and click "Send". Then immediately think, "oh no!" because you sent it to the wrong person. Or maybe you're checking out of an e-commerce website, click "Place Order" then a couple of minutes go by, and you have think, "I shouldn't have ordered that," and have buyer's remorse. You want to cancel or undo the action you just performed in both situations. Now put your developer hat on. How would you implement undo feature in these types of cases?
🔗 EventStoreDB
eventsto.re/codeopinion
🔔 Subscribe: / @codeopinion
💥 Join this channel to get access to a private Discord Server and any source code in my videos.
🔥 Join via Patreon
/ codeopinion
✔️ Join via KZhead
/ @codeopinion
📝 Blog: codeopinion.com
👋 Twitter: / codeopinion
✨ LinkedIn: / dcomartin
📧 Weekly Updates: mailchi.mp/63c7a0b3ff38/codeo...
0:00 Intro
0:53 Undo Example
2:20 Code Sample
4:47 Undo Implementation
10:09 Demo
#softwarearchitecture #softwaredesign #eventdrivenarchitecture
Have you implemented an undo feature? How did you go about doing it?
I tried it once with Memento pattern. I have to watch the entire video to understand how you do it :)
I did before with the command pattern. Watching the video now to see what you choose.
usually i store the initial value aswel it in a no sql db then i have versions and history and i can pick either the latest or a certain point to restore from UI
Ok, simply delaying commands was honestly not what I expected when I read the video title about implementing an undo concept. 🙂🙃
We can also implement this feature by first storing the tweet in a database with pending status and a timestamp. In background we can send the tweet or start the saga, if the process is more complex, using a policy that will consider tweets with pending status and a delay calculated from the timestamp. If before the delay timeout we receive a request to undo, we just mark the tweet as canceled by changing their status. After that, the policy will ignore the tweet.
What if during delay your consumer brakes? You loose the tweet? I don't see how it'll get a retry.
In the case of the queue being over burdened. How would one handle the fact that a undo command isn't "instant". Extra hidden timeout? Seems inflexible. Read max message time? Might not be possible and what if the message has the new highest delay.
Ya it's also worth noting that depending on throughput of your queue, you might not process the undo in-time before the timeout executes. I briefly mentioned as well, is that the timeout is implemented using delayed delivery. As always, trade-offs. Depending on tooling, you could make the undo be synchronous call from the client.
Great content as always. Could you please explain little more how the TweetWithDelay gets removed from message broker when you publish the UndoTweet event? Thanks
He explains it. Nothing is removed from message broker, just saga is marked as completed so after 10 sec message won't be processed because saga is already completed.
@@cybul2640 thanks for explaining, but are we checking somewhere if saga is completed?
@@idgafa we don't. Saga implementation in nservicebus takes care of it. Look at 12:45
Messaging Library (NServiceBus) is handling the saga and does that.
Why not use a client side only implementation though? Would make it so much easier imho ¯\_(ツ)_/¯
It will not work if eg user send tweet and leave a page. Tweet will not be sent and sotred in your case.
Ya I wanted to mention client-side but forgot to point this out. You could implement it client side only, however it's not durable if you close the client as it would be responsible for making the request to send the message. That may (or may not) be ideal. Depends on your use-case.