event driven architecture with legacy app

167 views
Skip to first unread message

Yoann R.

unread,
Apr 15, 2014, 4:57:50 PM4/15/14
to ddd...@googlegroups.com
Good evening,

I am currently working on a e-commerce web site.  I have three BCs at stake : a web site, the application which holds the management of the shopping cart and the application that deals with the various discounts available.

I am myself working on the shopping cart . I have an application on my server which hold the state of my cart and when receiving commands from the client execute the command and emits some events towards my client browser.

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.

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. 

It looks dumb to me But I do not see any other alternative. Am I overlooking something essential?

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 ?

thanks a lot for your reading,

Yoann


Yin Zhang

unread,
Apr 16, 2014, 3:21:25 AM4/16/14
to ddd...@googlegroups.com
If the discount is depends on the items in shopping cart, should it be strongly consistent?

James Nugent

unread,
Apr 16, 2014, 3:56:57 AM4/16/14
to ddd...@googlegroups.com
Hi,

To get a meaningful answer you’ll likely need to provide a lot more context than this…


James




On 16 Apr 2014, at 08:21, Yin Zhang <melclo...@gmail.com> wrote:

> If the discount is depends on the items in shopping cart, should it be strongly consistent?
>
> --
> You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Philip Jander

unread,
Apr 16, 2014, 4:16:00 AM4/16/14
to ddd...@googlegroups.com

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


Yoann R.

unread,
Apr 16, 2014, 5:13:04 PM4/16/14
to ddd...@googlegroups.com
Argh I tried my best to explain everything in a very few words ... it was not a huge success. :)

First of all, I must say that I am not doing everything by the book (blue or red). The project and the team I am involved with do not practice DDD and I am myself very much a learner...  all your answers made me think, which is not bad by itself... :)

Philip you are right, it is not a command I send to the discount BC. I use some .net instance in memory to help me querying the discounts available for a list of items.

The definition I know of different BC is that these BC do not share the same ubiquitous language. In my case, There are slight changes from the discount BC to the e-commerce web site. Discount in the web sites are bigger ensembles of discount in by the discount BC or so I understood so far. They are grouped together to be communicated to the customer.
Furthermore, handling a black box not knowing what might come out of it made me think of a different BC, but  may be I am mistaken.

I will try to be more precise on what I try to achieve. When the state of a cart changes on the server side, it is usually because of some AddItem command coming from the client app. My client app might query the state of the cart, but it may too be interested in only what has changed because it is less heavy. 
Executing a command, the server side can elaborate easily these kinds of "events" : departmentAddedToTheCart, departmentQuantityChanged, etc... because they are related to the addItem  command and because all these "events" deal with something known by the server side. 
I would like to be able to trigger these "events" when dealing with discounts too. But here I can only query the whole state, not the differences that adding my item to the cart might have produce in the discounts of the cart.

a little example :
Cart :
item  Qty      Price     Discount
a        2         2$              1$
b        3         5.5$           -

I add 4 c, my new cart with discounts is going to be 

item  Qty      Price     Discount
a        2         2$             -
b        3         5.5$           -
c        4        12$           5$

The first discount of one dollar on "a" has moved within "c" and was added to the 4$ to make 5.

The events I would be interested in having should be discountRemoved for a, and discountAdded for c of 5$.

mhhh doesn't feel like CQRS or DDD all that. The more I am writing here the less I feel like it is the place to ask it...
Thanks for your questions and links though, I will chew them a bit more on my own ...


Yoann











--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+unsubscribe@googlegroups.com.

Yin Zhang

unread,
Apr 16, 2014, 5:27:18 PM4/16/14
to ddd...@googlegroups.com

Do you need to track individual discount that happened in the cart, or just customer with these items have a discount of 5 dollars? It of course depends on your business case.

Regarding your discounted BC, it looks like a BC to manage discount rules and automatically sends mail campaign. If this is the case, instead of querying this BC, what about let this BC to notify the ordering BC when a discount rule been added or changed?

Query local BC guarantees your consistent of discount rules in shopping cart, and is much easier to do.

You received this message because you are subscribed to a topic in the Google Groups "DDD/CQRS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dddcqrs/6y5nT_TooLQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dddcqrs+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages