domain-driven design in legacy application

100
Legacy application Large ambitions A case study: how DDD helped deliver at Sungard Asset Arena Cyrille Martraire - @cyriux -

Upload: martraire-cyrille

Post on 06-Dec-2014

1.239 views

Category:

Technology


3 download

DESCRIPTION

A software editor in finance was facing the challenge to extend substantially the capabilities of its main application, despite 20 years of legacy in multiple technologies. In this talk, Cyrille Martraire will report on how DDD has been applied to capture deep models of the domain, within bounded contexts that emerged in the course of the project, and how DDD also helped to build a strategy for dealing with the legacy code. The video is available on Skillsmatter website: http://skillsmatter.com/podcast/design-architecture/applying-ddd-legacy-app

TRANSCRIPT

Page 1: Domain-Driven Design in legacy application

Legacy applicationLarge ambitions

A case study: how DDD helped deliver at Sungard Asset Arena

Cyrille Martraire - @cyriux -

Page 3: Domain-Driven Design in legacy application

LEGACY

Page 4: Domain-Driven Design in legacy application

Passionate developer

PARISSince 1999

@cyriux

Page 5: Domain-Driven Design in legacy application

Paris Software Craftsmanship Community

http://www.meetup.com/paris-software-craftsmanship/

Page 6: Domain-Driven Design in legacy application

Arolla

Arolla.fr

Page 7: Domain-Driven Design in legacy application

A Case Study

Page 8: Domain-Driven Design in legacy application

From a recent project (contract)

Every example is made-up to protect the innocent IP.

Page 9: Domain-Driven Design in legacy application

Once upon a time…

Page 10: Domain-Driven Design in legacy application

Large Ambition

Page 11: Domain-Driven Design in legacy application

Asset Management

Page 12: Domain-Driven Design in legacy application
Page 13: Domain-Driven Design in legacy application

Buy, Partner or Make?

Page 14: Domain-Driven Design in legacy application

Buy, Partner or Make?

Page 15: Domain-Driven Design in legacy application

Project Life

2010 2011 2012

+BA

+QA

+Dev Dev++

PHASE 1

PHASE 2 PHASE 3

PHASE 4

Page 16: Domain-Driven Design in legacy application

“You’ve got the right

skillsWe trust you.

Deliver”

Page 17: Domain-Driven Design in legacy application

So how do we do that?

Page 18: Domain-Driven Design in legacy application

?

Page 19: Domain-Driven Design in legacy application

Spike!

3-weeksDeliberate Discovery in mind

PHASE 1

Page 20: Domain-Driven Design in legacy application

Codeanalysis[Greg Young]

Within 3 weeks1. Conversations with experts2. Code the understanding & note questions3. Iterate

http://skillsmatter.com/podcast/design-architecture/mystery-ddd/js-4401

Page 21: Domain-Driven Design in legacy application

Find the Domain Experts

Page 22: Domain-Driven Design in legacy application

The of!cial expert(former Asset Manager)

Page 23: Domain-Driven Design in legacy application

Proxy Domain Experts

Page 24: Domain-Driven Design in legacy application

Proxy Domain Experts

Page 25: Domain-Driven Design in legacy application

Haz Context?

Sell-Side(Hedging) Broker

(A Vs. B)

Buy-Side(investment)

Accounting(tax, Basel etc)

Accounting(tax, accuracy, boring stuff)

+ fees!

“Trade” = ?

Page 26: Domain-Driven Design in legacy application

Fossilized Domain Expertise

http://newspaper.li/fossil/

Page 27: Domain-Driven Design in legacy application

Conversations !rst

• Ask *good* questions• Build respect and confidence

• Beware and care about synonyms and main concepts

http://journalism.about.com/od/reporting/tp/Finding-And-Developing-Ideas-For-News-Stories-And-Articles.htm

Page 28: Domain-Driven Design in legacy application

Sketching

Page 29: Domain-Driven Design in legacy application

Sketching

Page 30: Domain-Driven Design in legacy application

Sketching

Page 31: Domain-Driven Design in legacy application

An instrument is effective for a period of time (its life), that is the date range between the effective date and the expiry dateA swap is made of legs, each of them being an independent instrument on its own. Each leg defines two counterpartiesA payoff is a cash flow given by one counterparty to the other counterpartyInstruments generate cash flows during their life, in particular at expiry date (redemption, zero coupon) and at regular datesThere may be a date offset for settlements, fixings and cash flows paymentsFloating rate devices generate cash flows according to observation expressions based on some observable referenceFixed rate devices generate cash flows according to a predefined couponInflation-linked devices modulate the coupon, coupon rate or notional amount by the variation of some (inflation) observable referenceRegular dates may be predefined explicitly as a dates list, or as repeated dates defined by a period and a time direction (backward or forward), with stub convention and date adjustment rules, and according to some holiday calendarDate adjustment rules are defined by a day roll convention and a business centerA funding leg is a fixed rate device or a floating rate deviceA return leg is a leg that reproduces the exact cash flows of another instrument

A credit leg observes credit events from some identified instrument and triggers either a physical settlement or to a cash settlement. Typical credit events are bankruptcy, failure to pay, restructuringForward and Future means that the effective date is in the future. The difference between forward and future is that the former is OTC whereas the later is cleared, more standard, and involves frequent margin calls (hence a convexity bias between them)From a legal perspective, an option is the right to exercise some transaction, typically to buy/sell the underlying instrument at a predefined strike and volume, or to receive a payoff. Since investors are rational, we may also consider options to be essentially instruments with conditional transaction, in general payoffsOption styles are typically European (exercise only at expiry date), American (exercise anytime), Bermuda (exercise at regular dates), Canary (exercise at regular dates after some date or period)An underlying instrument is an instrument used to condition the exercise (which may be automatic) and often used to calculate the amount of the payoff or more that is directly the object of an exchange, in the case of an exchange of assetsSome instruments are subject to conversion, i.e. they can be replaced with another instrumentSome instruments involve one, two or no exchange(s) of principal(s)Compounding swaps capitalize interests earned for each period payment period

Cash Flow

Bank HolidayInterest rate

Growing our Ubiquitous Language

Collecting scenarios

Page 32: Domain-Driven Design in legacy application

Taking notes, in code

Class, interface names & documentationFieldsRelationships (if any)

+ Behavior!

Page 33: Domain-Driven Design in legacy application

Code doesn’t lie

Got something wrong?Forgot something?

It shows!

Page 34: Domain-Driven Design in legacy application

Found a metaphor

http://www.marksmart.net/gearhack/pogomoog/pogomoog.html

Page 35: Domain-Driven Design in legacy application

Found a metaphorModular Synthesizer

Martin Russ - http://eetimes.com/design/audio-design/4238388

Page 36: Domain-Driven Design in legacy application

Found a metaphorIn Java code

Output of a class/function is the input

of another

Page 37: Domain-Driven Design in legacy application
Page 38: Domain-Driven Design in legacy application

So let’s keep on coding and rebuilding

everything!

Sounds like a great idea!

Page 40: Domain-Driven Design in legacy application

Plenty of Legacy code working since 1993

Redoing = waste + risk

Page 41: Domain-Driven Design in legacy application

Still need to redo some parts

How do we integrate with legacy?Where do we stop redoing?

Page 42: Domain-Driven Design in legacy application

Legacy strategy

Know your enemiesAsset Capture & Strangler Application

Bubble Context & ACLScream it loud

PHASE 2

Page 43: Domain-Driven Design in legacy application

Know your enemies[discover the app]

Read the documents

Interview peopleUse the application

Read the code

Fix bugs

Page 44: Domain-Driven Design in legacy application

Visualize[primary "ow & support features]

http://www.fimarkets.com/pagesen/back-middle-front-office.php

Page 45: Domain-Driven Design in legacy application

Visualize[primary "ow & support features]

http://www.fimarkets.com/pagesen/back-middle-front-office.php

Page 46: Domain-Driven Design in legacy application

Visualize[primary "ow & support features]

http://www.fimarkets.com/pagesen/back-middle-front-office.php

Page 47: Domain-Driven Design in legacy application

http://staff.bath.ac.uk/enssa/LPDev.htm

Asset Inventory

Page 48: Domain-Driven Design in legacy application

Asset Capture

http://martinfowler.com/bliki/AssetCapture.html

Engine

Exhaust

Transmission

Page 49: Domain-Driven Design in legacy application

Asset Capture

Focus on one single asset : the engine

http://martinfowler.com/bliki/AssetCapture.html

Engine

Exhaust

Transmission

Page 50: Domain-Driven Design in legacy application

Strangler application

A new module will progressively

strangle the former one, for one single

asset only

http://www.flickr.com/photos/louisfoecy/4114597043

http://martinfowler.com/bliki/StranglerApplication.html

Page 51: Domain-Driven Design in legacy application

Conservative by default

• Keep existing architecture– N-tiers, application server,

middleware– Same database– Same UI technology

– (Almost) all the legacy code

Diagrams shamelessly stolen from Eric Evans DDDx 2011 talk

Page 52: Domain-Driven Design in legacy application

Bubble Context

• Create a little bubble of innovation

• Brand new model

• As clean as we like• Highly tested• High hygiene standards

Page 53: Domain-Driven Design in legacy application

Bubble Context

• ACL to protect from the legacy code

• Translates legacy objects & services into new, cleaner ones

Page 54: Domain-Driven Design in legacy application

Strangler (cont.)

• Progressively turn off legacy functionalities & turn on the new ones

Page 55: Domain-Driven Design in legacy application

Agree on maxims[communicate the plan]

• “Only one work site at a time: instruments”

• “When in Rome, do as Romans do”

Page 56: Domain-Driven Design in legacy application

Scaling development in the bubble context

Infect the teamCode as SPOT

High hygiene standardsFunctional-style

PHASE 3

Page 57: Domain-Driven Design in legacy application
Page 58: Domain-Driven Design in legacy application

I only care about Java EE 6

Page 59: Domain-Driven Design in legacy application

Hey! Finance is cool!

Page 60: Domain-Driven Design in legacy application
Page 61: Domain-Driven Design in legacy application

Oh, this domain is

really cool!

Page 62: Domain-Driven Design in legacy application

Oh, this domain is

really cool!I’d like to know it better!

Page 63: Domain-Driven Design in legacy application

Invest in domain knowledge

• Bi-weekly 30mn training sessions

Page 64: Domain-Driven Design in legacy application

Signal to Noise ratio

http://www.flickr.com/photos/28471130@N07/2666802097

Page 65: Domain-Driven Design in legacy application

Signal to Noise Ratio

• SNR ≥ 80 %

• Signal: CashFlow, CashFlowSequence, CashFlowEngine, FinancialProduct, BankHolidays, ReferenceData

• Noise: CashFlowBuilder, CompositeEngine, ProductFactory, BankHolidaysDecorator

Page 66: Domain-Driven Design in legacy application

“All what you explained is nice, but what about

the actual code and

design?”

-client

Page 67: Domain-Driven Design in legacy application

Code as reference[export the glossary]

• Annotate domain-relevant classes

• Custom Doclet to export Excel-formatted glossary of every domain concept

• Send directly to end customers as reference documentation

Page 68: Domain-Driven Design in legacy application

High hygiene standards[in the bubble context]

• Dependencies– Legacy– Middleware– Frameworks– Database stuff

null + TDD, BDD+ Clean Code

Page 69: Domain-Driven Design in legacy application

“Functional-First” style

Page 70: Domain-Driven Design in legacy application

“Functional-First” style

• Value Objects (Quantity, Range…) as much as possible– Immutable

• Side-effect-free functions• Closure of operations

– CashFlow and CashFlowsSequence add(), negate(), multiply()

Page 71: Domain-Driven Design in legacy application

Legacy: the bigger picture

Clarify bubble boundariesEmerging contexts

Shock absorberResponsibility layers

PHASE 4

Page 72: Domain-Driven Design in legacy application

First boundaries

<<ValueObject

<<ValueObject

<<ValueObject>><<ValueObje

ct<<ValueObject>>

<<Service>><<SPI>>

<<Service>><<API>>

<<Entity>><<Aggregate>>

Page 73: Domain-Driven Design in legacy application

boundaries 2.0

<<ValueObject

<<ValueObject

<<ValueObject>><<ValueObje

ct<<ValueObject>>

<<Service>><<SPI>><<Service>>

<<API>>

<<Entity>><<Aggregate>>

Look Ma: no entity in there!

Page 74: Domain-Driven Design in legacy application

boundaries 2.0

<<ValueObject

<<ValueObject

X<<ValueObject>>

<<ValueObject

<<ValueObject>>

<<Service>><<SPI>><<Service>>

<<API>>

X<<Entity>>

<<Aggregate>>

As Value Object inside

As Entity outside

Page 75: Domain-Driven Design in legacy application

Just a lib & side-effect free!

<<ValueObject

<<ValueObject

<<ValueObject>><<ValueObje

ct<<ValueObject>>

<<Service>><<SPI>><<Service>>

<<API>>

Values in Values out

Page 76: Domain-Driven Design in legacy application

API

SPI

Page 77: Domain-Driven Design in legacy application

ACL-backed Domain service

• Unify *many* legacy services through one single & simple interface

• Hide the most unfriendly legacy code

<<ACL>><<Facade>>

<<old stuff I don’t want to deal with>>

Page 78: Domain-Driven Design in legacy application

Initial journey toward our dream model

Bespoke custom DREAM MODEL

Page 79: Domain-Driven Design in legacy application

Dream model must pass every scenario

Bespoke custom DREAM MODEL

Given a floating rate bond on EURIBOR 3MAnd a nominal of 15M EURAnd an issue date of 2011/06/15And an end date of 2012/06/14And an SEMI_ANNUAL calculation period

When the EURIBOR 3M evolves:| 2011/09/15 | 3.5% | | 2012/03/15 | 4.0% |

Then the cash-flows are:| 2011/12/13 | 23000 || 2012/06/14 | 25500 |

Page 80: Domain-Driven Design in legacy application

Deliberately easier by construction

Bespoke custom library

Page 81: Domain-Driven Design in legacy application

Con"icting aspects suggest several contexts

“I don’t need all these data to do that, I just need these 3 fields”

Page 82: Domain-Driven Design in legacy application

Context Game[Greg Young]

“What's your ideal <instrument>?”• Pre-trade: very liquid with a narrow bid – offer

spread• Trading: unique identifier easy to key in• Risk: has risk on a single risk factor• Back-office: very few cash-flows that are

certain and known long beforehand

Page 83: Domain-Driven Design in legacy application

Trading<<legacy>>

Risk<<legacy>>

Cash-flows<<strangler>>

CRUD<<legacy POJO>>

DB<<legacy>>

Hibernate ORM

Contexts that emerged

Page 84: Domain-Driven Design in legacy application

Trading<<legacy>>

Risk<<legacy>>

Cash-flows<<strangler>>

CRUD<<legacy POJO>>

DB<<legacy>>

Hibernate ORM

Contexts that emerged

Page 85: Domain-Driven Design in legacy application

Trading<<legacy>>

Risk<<strangler>>

Cash-flows<<strangler>>

CRUD<<legacy POJO>>

DB<<legacy>>

Hibernate ORM

Contexts that emerged

Page 86: Domain-Driven Design in legacy application

Trading<<legacy>>

Risk<<strangler>>

Cash-flows<<strangler>>

CRUD<<legacy POJO>>

DB<<legacy>>

Hibernate ORM

Team /manager invoke DRY

“I don’t want to maintain more models, it’s already hard enough!”

Page 87: Domain-Driven Design in legacy application

Trading<<legacy>>

Risk<<strangler>>

Cash-flows<<strangler>>

CRUD<<legacy POJO>>

DB<<legacy>>

Hibernate ORM

Team /manager invoke DRY

“I don’t want to maintain more models, it’s already hard enough!”

No it’s less maintenance!

Page 88: Domain-Driven Design in legacy application

Trading<<legacy>>

Risk<<strangler>>

Cash-flows<<strangler>>

CRUD<<legacy POJO>>

DB<<legacy>>

Hibernate ORM

How do we integrate?

?

Page 89: Domain-Driven Design in legacy application

Trading<<legacy>>

Risk<<strangler>>

Cash-flows<<strangler>>

CRUD<<legacy POJO>>

DB<<legacy>>

Non DDD (anemic),

already there

Hibernate ORM

Contexts Mappings

Page 91: Domain-Driven Design in legacy application

ACL as Shock Absorbers

http://www.monition.com/images/shaft-alignment-training.jpg

Page 92: Domain-Driven Design in legacy application

“That’s useless code!”

Page 93: Domain-Driven Design in legacy application

No, ACL’s are good!

Page 94: Domain-Driven Design in legacy application

“Ok so I will automate”

Page 95: Domain-Driven Design in legacy application

No, hand-crafted code is good!

Page 96: Domain-Driven Design in legacy application

Happy End

Project deliveredOn required scope

On timeClient satisfaction

CONCLUSION

Page 97: Domain-Driven Design in legacy application

Some remarks

• “DDD + R&D potential”: my projects selection criteria

• DDD: subtle, often not quite *sure*

• Don’t preach, tell the benefits

Page 98: Domain-Driven Design in legacy application

The future

• Keep on growing the model in the bubble context

• Reuse in another context (e.g. accounting)? - To what extent?

• The bubble may break at some point

Page 99: Domain-Driven Design in legacy application

Questions?

You can also ask me later!

Page 100: Domain-Driven Design in legacy application

Merci