Hi Yoann,
it is difficult to answer this without knowing the structural design of
the discounts (i.e. more like the "save 15% for all purchases over $200
total during easter holidays" kind or more of the personalized coupon
style, or depend on personalized data, e.g. prior sales volume, or mixed).
So my answer below needs some interpretation to fit your actual use case.
> In order to get the discounts available, I send a command that include
> the state of my cart to the discount BC which in turn gives me the
> discounts available for this cart.
First, to me this sounds overly complicated: sending commands to
initiate a calculation the result of which is only used temporarily, is
an antipattern.
I would send a command to change the state of the discounts BC, i.e. to
initiate or modify a campaign. I would send a query to the discounts BC
to get the current discount campaigns data. You would use a service
(read: locally available .net instance which either knows how to query
discounts or is provided with the current discounts data on
instantiation) in order to calculate concrete discounts for a given
shopping cart.
The only case where I would actually have commands going from cart (or
rather checkout!) to discounts is if the discounts available need to be
modified in response to a checkout, i.e. a coupon is invalidated after
being used.
>
> The thing is I would like to know what has changed in the discounts.
> My first guess is to create an ACL which makes the delta between
> the discounts available before the command being issued and the new
> discounts just received in order to emit just the right events to tell
> afterwards my web site.
What would be the reason for the discounts to change? In response to
changed content of the shopping cart? Or in response to changed
campaigns, e.g. because the cart was left "open" over the end of the
discount campaign?
If you have a local "Discounts" instance, which tells you the applicable
discounts for a given shopping cart, can you simply calculate those on
the fly?
>
> It looks dumb to me But I do not see any other alternative. Am I
> overlooking something essential?
I have the impression - although of course I might be completely
mistaken - that you are confusing bounded contexts/business components
with units of deployment, aka tiers/servers/hosts/processes? As a result
you are under the impression, that code related to discounts must reside
in a different run time location that code related to shopping carts?
Instead, a BC can and should consist of code distributed among physical
locations. E.g. the server which is responsible for working with the
carts may have a local instance of a class belonging to the discounts BC
(which is provided with a means to communicate with the server
responsible for holding the discount campaigns). Maybe the shopping cart
doesn't even need to be concerned with discounts at all. You could
simply use the web server to display applicable discounts for a given
shopping cart and only on checkout need the discounts be actually applied.
There was a nice talk by Udi Dahan at DDDx 2011 on composite
applications which as I recall clarifies this:
https://skillsmatter.com/skillscasts/1806-talk-from-udi-dahan
> It looks to me like a standard legacy problem. Do you know any good
> resource about how to introduce event driven architecture in legacy
> systems ?
At the same DDDx Eric Evans talked about how to migrate legacy software.
While this was geared towards DDD and not events, I believe it is
generally applicable.
My rules of engagement are: 1. envison an interface to the legacy part
you need to used as it should look like from a non-legace perspective.
2. make an acl that implements the new interface but talks to the legacy
part. 3. use that interface from shiny new software. 1a: don't overdo
the envisioning - it should be possible to continue with step 2 after
step 1.
Maybe you can specify the situation of your software a bit more, much of
the answer is based on speculation ;)
>
> thanks a lot for your reading,
You're welcome
Cheers
Phil