Architecture Weekly #120 - 27th March 2023
Welcome to the new week!
Let’s say that we’d like to enforce the uniqueness of the user email. Theoretically, you could query a read model keeping all users’ data and check if the user with the selected email already exists. Easy peasy? It sounds like it, but it’s not. Such an approach will give you a false guarantee. In the meantime, between you got the result, ran your business logic and stored new user information, someone could have added a user with the same email. Querying is never reliable; we should tell, not ask. So, in this case, claim the user email end either succeed or fail.
Unique constraint validation is one of those things that looks simple but is not always easy. From my experience, a unique constraint requirement usually indicates that our business people bring us a solution instead of a problem. We should ensure that what we’re trying to provide here is a real requirement and ask enough whys before we commit to it.
Still, sometimes we need to select the hill we’d like today for or just need to do our stuff.
In Marten, we're trying to show the pragmatic face of Event Sourcing and embrace that whether something is best practice or anti-pattern depends on the context. I wrote about the pragmatic trick that can simplify uniqueness constraint enforcement in Event Sourcing when using Marten.
I struggled to create code for the starting phase showing the common architecture/implementation flaws. I was even considering paying some junior to write such. I needed a code to be the starting point for my new workshop, Event Sourcing in production. Now I found a solution and started to use ChatGPT. The code it generates seems to be a perfect match for such needs!
Jokes aside. The tool is impressive, and I strongly believe it's a must-have nowadays as it speeds up boilerplate work enormously.
I remember the days before there was StackOverflow, and we somehow could write code; we also weren't fired (as was predicted 10 years ago) because of it. Did our work change? Sure? Is it better or worse? It's different.
And that's great; we just need to adapt and find a good way of using this tool. I'm considering it a chance to focus on what's important.
Working with ChatGPT reminded me to pair coding with a skilled coder but a bad programmer. You will get decent results if you drive it well, but it won't set architecture for you. It's a tool that reminds me Memento plot. A guy that has old memories remember what happened a minute ago but forgets what we talked 10m ago and is not able because of that to be too creative.
See the current result in the repo: https://github.com/oskardudycz/event-sourcing-on-prod-workshop/.
If you’d like to learn more about why this code, even if it’s looking pretty well, has serious flaws to consider using on prod, contact me, and let’s organise the training for you and your colleagues. See details on my workshops page.
See also more about the application code generation based on ChatGPT and related tools in:
See also a great write-up to see how it works to understand its limitations:
TLDR, no need to be afraid that we’ll be replaced; we’ll still need to move tickets in our backlogs, talk to humans and work with them. But the chance is that we’ll have more time for what’s more important and do it better, e.g.:
We’ll still have dramas, like the latest Docker drama. Maybe they used ChatGPT to make decisions and write the email for them? Or maybe they did not but should have been?
I’m almost sure that no ChatGPT was involved in making such impressive migrations
But no worries, no ChatGT was and will be involved in writing Architecture Weekly or my blog!
Check also other links!
p.s. I invite you to join the paid version of Architecture Weekly. It already contains the exclusive Discord channel for subscribers (and my GitHub sponsors), monthly webinars, etc. It is a vibrant space for knowledge sharing. Don’t wait to be a part of it!
p.s.2. Ukraine is still under brutal Russian invasion. A lot of Ukrainian people are hurt, without shelter and need help. You can help in various ways, for instance, directly helping refugees, spreading awareness, and putting pressure on your local government or companies. You can also support Ukraine by donating, e.g. to the Ukraine humanitarian organisation, Ambulances for Ukraine or Red Cross.