softshake 2015 - domainmodel.stream()

53
DomainModel.stream()

Upload: gdigugli

Post on 06-Apr-2017

773 views

Category:

Data & Analytics


2 download

TRANSCRIPT

Page 1: SoftShake 2015 - DomainModel.stream()

DomainModel.stream()

Page 2: SoftShake 2015 - DomainModel.stream()

DOMAINMODEL.STREAM()https://github.com/lesfurets/model­map

Page 3: SoftShake 2015 - DomainModel.stream()

WELCOME TO THE FURETS !

Page 4: SoftShake 2015 - DomainModel.stream()

@GDIGUGLI – GILLES DI GUGLIELMODesigner of sweet cooked software since 1999Software Architect at LesFurets.com

@JUBAUDRY – JULIEN BAUDRYJava Developer since 2007Software Architect at LesFurets.com

Page 5: SoftShake 2015 - DomainModel.stream()
Page 6: SoftShake 2015 - DomainModel.stream()
Page 7: SoftShake 2015 - DomainModel.stream()
Page 8: SoftShake 2015 - DomainModel.stream()

1 website, 5 Insurance Products : Car, Health, Home, Bike, Loan1 codebase, 450k lines of code, 60k unit tests, 150 selenium tests

22 Developers, 2 DevOps, 3 Architects10+ production servers

1 release per day7 years of code history

2.5M quotes/year, 31% of market share

Page 9: SoftShake 2015 - DomainModel.stream()

DOMAIN MODEL, WHAT DO YOU MEAN ?

Page 10: SoftShake 2015 - DomainModel.stream()

MOVING THE ARCHITECTURE

Page 11: SoftShake 2015 - DomainModel.stream()

ARCHITECTURE BUZZ

Copy on writeImmutable dataNoSQLClustered Data BaseData streamingMicro batchingLambda architectureData on demand

Page 12: SoftShake 2015 - DomainModel.stream()

WHAT YOU HAVE ...

Page 13: SoftShake 2015 - DomainModel.stream()

WHAT YOU WANT …

Page 14: SoftShake 2015 - DomainModel.stream()

YOU ARE IN TROUBLE ...

Page 15: SoftShake 2015 - DomainModel.stream()

FRONT APP EVOLUTIONS

Your domain model is cloned using twodifferent languages.

Governance of the domain model andchange requests are difficult toimplement.

Development owners of the server andfront application are different.

UI Spaghetti code.

Page 16: SoftShake 2015 - DomainModel.stream()

FRONT STORAGE EVOLUTIONS

Mapping entities in Cassandra is painful.

Don’t migrate your Entity/Relation modelusing cut & paste!

You should probably flat your domainmodel to fit a single row.

Infinite storage.

Page 17: SoftShake 2015 - DomainModel.stream()

BACKOFFICE EVOLUTIONS

A lot of rework to implement.

Spark and ML­lib love datavectors.

Spark read raw data, aggregate,write them in microbatches.

No more (very long) nightlybatches.

Full history is available forcustom computations.

Page 18: SoftShake 2015 - DomainModel.stream()

WHAT WE DO NOW ?

Page 19: SoftShake 2015 - DomainModel.stream()

ADD KEYS EVERYWHERE !

Page 20: SoftShake 2015 - DomainModel.stream()

A BIT OF DECORATION

Page 21: SoftShake 2015 - DomainModel.stream()

LET'S START WITH THIS MODEL...

Page 22: SoftShake 2015 - DomainModel.stream()

... AND TRANSFORM IT TO A KEY­VALUE MODEL

Page 23: SoftShake 2015 - DomainModel.stream()

USER MODEL

Page 24: SoftShake 2015 - DomainModel.stream()

USER MODEL

Page 25: SoftShake 2015 - DomainModel.stream()

USER MODEL

Page 26: SoftShake 2015 - DomainModel.stream()

ACCOUNT MODEL

Page 27: SoftShake 2015 - DomainModel.stream()

ACCOUNT MODEL

Page 28: SoftShake 2015 - DomainModel.stream()

ACCOUNT MODEL

Page 29: SoftShake 2015 - DomainModel.stream()

ACCOUNT MODEL

Page 30: SoftShake 2015 - DomainModel.stream()

ACCOUNT MODEL

Page 31: SoftShake 2015 - DomainModel.stream()

FROM DOMAIN MODEL TO KEY­VALUE MODEL

Step 1 : create one Enumeration with all keys

Step 2 : annotate your domain model

Step 3 : generate the key value model

Page 32: SoftShake 2015 - DomainModel.stream()

LET'S SEE THE DOMAIN MODEL & THE KEY­VALUE MODEL

Page 33: SoftShake 2015 - DomainModel.stream()

STEP 1 : ONE ENUMERATION WITH ALL KEYSone literal for each keyposition (optional) : used when collections are denormalizedtag (optional) : used to add meta­information

Page 34: SoftShake 2015 - DomainModel.stream()

STEP 2 : ONE ANNOTATION TO ANNOTATE THE DOMAINone method to retrieve the FieldIdone method to retrieve the Constraint

Page 35: SoftShake 2015 - DomainModel.stream()

STEP 3 : ANNOTATE YOUR DOMAIN MODELattribute, getter or setter can be annotatedgetter and setter must follow Java naming conventions

Page 36: SoftShake 2015 - DomainModel.stream()

STEP 4 : GENERATE THE KEY VALUE MODEL

Page 37: SoftShake 2015 - DomainModel.stream()

... JUST ONE LITTLE ISSUE.

Page 38: SoftShake 2015 - DomainModel.stream()

ACCOUNT & USER ID

sampleModel.getUser().getId()

Page 39: SoftShake 2015 - DomainModel.stream()

ACCOUNT & USER ID

sampleModel.getAccount().getId()

Page 40: SoftShake 2015 - DomainModel.stream()

MANY KEY FOR A SINGLE ATTRIBUTEEach key must have a unique path to retrieve its valueHow to retrieve the right value for each field?getAccount().getId()? getUser().getId()?

Page 41: SoftShake 2015 - DomainModel.stream()

SOLUTION : CONSTRAINTS

One for each field, specify which getter to use

Page 42: SoftShake 2015 - DomainModel.stream()

ADD A CONSTRAINT FOR EACH ANNOTATIONthe code generator only use the path with the specified gettereach field is now mapped correctly

Page 43: SoftShake 2015 - DomainModel.stream()

LET THE MAGIC BEGIN ...

Page 44: SoftShake 2015 - DomainModel.stream()

CODE GENERATOR UNDER THE HOOD

Execution is done using a maven pluginAnnotated properties are processed using Java Reflection

Generate handwritten style code, easy to readEnable JIT optimisations by combining lambdas and enumerationsLightweight pattern, designed for performance

Page 45: SoftShake 2015 - DomainModel.stream()

GENERATION OUTPUT (1/3)

Page 46: SoftShake 2015 - DomainModel.stream()

GENERATION OUTPUT (2/3)

An Enumeration containing metadate : type, generics type

Page 47: SoftShake 2015 - DomainModel.stream()

GENERATION OUTPUT (3/3)

a CSV containing each field, path, and value type

Page 48: SoftShake 2015 - DomainModel.stream()

USAGES ARE UNLIMITED

Page 49: SoftShake 2015 - DomainModel.stream()

YOU CAN USE JAVA 8 STREAM ON YOUR DOMAIN MODEL !FieldModel#stream() : a stream of key/value pair (FieldId/Object)FieldModel#parallelStream() : parallel stream and better performanceEasy use a filter/map/reduce operations on a domain model

Could you write a domain model diff tool now ?

Page 50: SoftShake 2015 - DomainModel.stream()

WHERE WE USE IT AT LESFURETS.COMSimple UI binding by replacing JSON model by a Dictionary (80% less code)Use JSON Dictionary for client/server RPC

Batch and ETL with an email provider (90% less code)Persistence in cassandra (from scratch with 200 lines of code for a whole model)

Injecting user data in selenium (40% less code)Mocking our domain model in thousand of unit tests

... everything in iterative fashion during the past 2 years.

Page 51: SoftShake 2015 - DomainModel.stream()

FUTURE AND IDEASPush as OSS our Cassandra serialisation codePush some Spark samplesJEP 276: Dynamic Linking of Language­Defined Object Models

Page 52: SoftShake 2015 - DomainModel.stream()

MODEL­MAP AVAILABLE ON GITHUB

http://github.com/lesfurets/model­mapFramework and examples

Apache LicenceTry it and contribute !

Page 53: SoftShake 2015 - DomainModel.stream()

THANK YOU!