Slide 1

Slide 1 text

One size does not fit all Stefan Tilkov
 @stilkov GOTO London 2016

Slide 2

Slide 2 text

Building blocks procedures functions libraries modules units objects classes images dynamic libraries shared objects components services microservices VMs containers lambdas

Slide 3

Slide 3 text

Commonalities dependencies boundary interface environment implementation

Slide 4

Slide 4 text

How big shall each individual piece be?

Slide 5

Slide 5 text

Just make things the right size

Slide 6

Slide 6 text

Separate separate things Join things that belong together

Slide 7

Slide 7 text

Information Hiding “[I]t is almost always incorrect to begin the decomposition of a system into modules on the basis of a flowchart. We propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change. Each module is then designed to hide such a decision from the others.” David L. Parnas, 1971 http://www.cs.umd.edu/class/spring2003/cmsc838p/Design/criteria.pdf

Slide 8

Slide 8 text

Separation of concerns “Let me try to explain to you, what to my taste is characteristic for all intelligent thinking. It is, that one is willing to study in depth an aspect of one's subject matter in isolation for the sake of its own consistency, all the time knowing that one is occupying oneself only with one of the aspects. […] It is what I sometimes have called "the separation of concerns", which, even if not perfectly possible, is yet the only available technique for effective ordering of one's thoughts, that I know of. This is what I mean by "focussing one's attention upon some aspect": it does not mean ignoring the other aspects, it is just doing justice to the fact that from this aspect's point of view, the other is irrelevant. It is being one- and multiple-track minded simultaneously.” Edsger W. Dijkstra, 1974 http://www.cs.utexas.edu/users/EWD/ewd04xx/EWD447.PDF

Slide 9

Slide 9 text

Single Responsibility Principle “A class [or module] should only have one reason to change. […] The SRP is one of the simplest of the principles, and one of the hardest to get right. Finding and separating those responsibilities from one another is much of what software design is really about.” “There is a corrolary here. An axis of change is only an axis of change if the changes actually occur.” Robert C. Martin, 1995/2003 http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

Slide 10

Slide 10 text

High Cohesion Loose Coupling

Slide 11

Slide 11 text

Vocabulary http://vanderburg.org/blog/Software/Development/cohesion.rdoc inherent: existing in something as a permanent, essential, or characteristic attribute adhesive: able to stick fast to a surface or object; sticky: cohesive: characterized by or causing cohesion cohesion: the action or fact of forming a united whole;
 in physics: the sticking together of particles of the same substance

Slide 12

Slide 12 text

Cohesion in OO: Object Calisthenics 1. One level of indentation per method 2. Don’t use the ELSE keyword 3. Wrap all primitives and strings 4. First class collections 5. One dot per line 6. Don’t abbreviate 7. Keep all entities small 8. No classes with more than two instance variables. 9. No getters/setters/properties 10. No static methods other than factory methods Jeff Bay, 2008 – http://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf

Slide 13

Slide 13 text

Indicators of strong cohesion simple to understand simple to explain one reason to change one stakeholder difficult to split (re-)used as a whole

Slide 14

Slide 14 text

Indicators of weak cohesion hard to understand difficult to explain many reasons to change multiple stakeholders obviously divisible partially re-used

Slide 15

Slide 15 text

Forces for separation Different environments (scale, performance, security, …) Parallel/isolated runtime Crosscutting concerns Frequency of change Parallel/isolated development Need for reuse Technical dependencies Domain dependencies Implementation Weight

Slide 16

Slide 16 text

Multiple Dimensions Different Priorities

Slide 17

Slide 17 text

System Persistence Logic UI Module A Module B Module C

Slide 18

Slide 18 text

System A Persistence Logic UI System B Persistence Logic UI System C Persistence Logic UI

Slide 19

Slide 19 text

Environments

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Environments Language runtimes Application servers Container Hosts Operating Systems Hardware Supervisors

Slide 23

Slide 23 text

Let’s talk about Microservices

Slide 24

Slide 24 text

Microservices – Common Traits > Focused on “one thing” > Autonomous operation > Isolated development > Independent deployment > Localized decisions

Slide 25

Slide 25 text

Example: Pricing Engine > Default product prices > General discounts > Customer-specific discounts > Campaign-related rebates Event Bus/Infrastructure

Slide 26

Slide 26 text

Super-small, really micro, nano > As small as possible > A few hundred lines of code or less > Triggered by events > Communicating asynchronously Characteristics: As seen on: > Any recent Fred George talk > Serverless Architecture(*) > AWS Lambda (*) https://leanpub.com/serverless

Slide 27

Slide 27 text

Super-small, really micro, nano > Close collaboration – common goal > Shared strong infrastructure dependency > Common interfaces, multiple invocations > Close similarity to actor-based environments > Well suited to decomposable/“fuzzy” business problems Consequences:

Slide 28

Slide 28 text

Example: Product Detail Page > Core product data > Prose description > Images > Reviews > Related content Orchestration

Slide 29

Slide 29 text

Small, micro > Small, self-hosted > Communicating synchronously > Cascaded/streaming > Containerized Characteristics: As seen on: > Netflix > Twitter > Gilt

Slide 30

Slide 30 text

Small, micro > Close collaboration – common goal > Need for resilience/stability patterns for invocations > Often combined with parallel/streaming approach > Well suited to environments with extreme scalability requirements Consequences:

Slide 31

Slide 31 text

Example: E-Commerce Site > Register & maintain account > Browse catalog > Search > See product details > Checkout > Track status

Slide 32

Slide 32 text

Medium-sized > Self-contained, autonomous > Including UI + DB > Possibly composed of smaller microservices Characteristics: As seen on: > Amazon > Groupon > Otto.de > Self-contained systems (SCS)(*) (*) https://scs-architecture.org

Slide 33

Slide 33 text

Medium-sized > Larger, independent systems > Including data + UI (if present) > Able to autonomously serve requests > Light-weight integration, ideally via front-end > Well suited if goal is decoupling of development teams Consequences:

Slide 34

Slide 34 text

Building Block 0..1 *

Slide 35

Slide 35 text

Hierarchy & Rule Example * * * * * Class Package Module Service System Method > Systems communicate async, use front-end integration > Subsystems can use sync calls via facades > Modules only depend on modules of lower layers > Packages must not have circular dependencies > Classes within a package can collaborate closely > Methods must not call beyond depth 2

Slide 36

Slide 36 text

Different modularization levels Different rules & strategies

Slide 37

Slide 37 text

* * * * * Class Package Module Subsystem System Method * Class Package Module Subsystem System Method Service * * * * * * Class Package Module Subsystem System Method Service * * * * * * Class Package Subsystem System Method * * * * Service Subsystem System Service * * * * * Functions Actors Modules

Slide 38

Slide 38 text

Microservice Sizing Antipatterns

Slide 39

Slide 39 text

Antipattern: Decoupling Illusion Stakeholder Stakeholder Stakeholder Platform Person

Slide 40

Slide 40 text

Antipattern: Anemic Service Process Flow Presentation Domain Logic Data JDBC in disguise Useful and specific Re-usable but low- level

Slide 41

Slide 41 text

Antipattern: Unjustified Re-Use Invoice Handling Direct Marketing E-Mail Hash Table Templating Printing Spell Check String Concatenate

Slide 42

Slide 42 text

Lessons learned

Slide 43

Slide 43 text

What doesn’t: Mentioning the word “meta-model” What works: Being explicit about your meta-model

Slide 44

Slide 44 text

What doesn’t: Over-regulating everything What works: Separating macro and micro decisions

Slide 45

Slide 45 text

What doesn’t: Fleeing into technicalities What works: Trusting your gut and making a good guess

Slide 46

Slide 46 text

What doesn’t: Center around technical commonality What works: Use organization and its use cases as level 0 driver

Slide 47

Slide 47 text

What doesn’t: Aim for perfection and stubbornly stick to it What works: Prepare to be wrong on every level

Slide 48

Slide 48 text

Stefan Tilkov
 stefan.tilkov@innoq.com
 Phone: +49 170 471 2625 innoQ Deutschland GmbH Krischerstr. 100 40789 Monheim am Rhein Germany Phone: +49 2173 3366-0 innoQ Schweiz GmbH Gewerbestr. 11 CH-6330 Cham Switzerland Phone: +41 41 743 0116 www.innoq.com Ohlauer Straße 43 10999 Berlin Germany Phone: +49 2173 3366-0 Ludwigstr. 180E 63067 Offenbach Germany Phone: +49 2173 3366-0 Kreuzstraße 16
 80331 München Germany Phone: +49 2173 3366-0 @stilkov That’s all I have, thanks for listening.

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

Image Credit David Mellor Kitchen Knives, https://flic.kr/p/pyW8xB Alice Popkorn, https://flic.kr/p/5NsmsK hairchaser, https://flic.kr/p/aqNWyV