37
That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my monkeys! Rob Martin / Version2beta LambdaDays 2017, Kraków, Poland

That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

That's my monkey

A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture:

This is my circus, and those are my monkeys!

Rob Martin / Version2beta LambdaDays 2017, Kraków, Poland

Page 2: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

What is a Senior?

“Everyone can be taught to sculpt. Michelangelo would have

had to be taught how not to.” - Alan Perlis

“Your first 10,000 photographs are your worst.”

- Henri Cartier-Bresson

Page 3: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

What is a 10x developer?

KSLOC?

Function points?

Cyclomatic complexity?

Constructive cost modeling?

Value.

Page 4: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

What is value?

Build tools for others to build richer lives

Quick and frequent delivery with prompt feedback

Page 5: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

The 10x developer

0

2.5

5

7.5

10 1.25 ^ 10 = 9.31x

1.0 ^ 10 = 1.0x

0.75 ^ 10 = 0.056x

Value

Page 6: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Creating 10x developers

Workshops

Internships

Master - Apprentice

Mob programming

Code reviews

Page 7: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Deliver Value Quickly (or, Can we survive our success?)

Rounded up, all startups fail

Expediencies: scripting languages, monolithic frameworks, popular libraries

Expediency means Shortcuts that cause Problems

Difficult to maintain, difficult to scale

Our users lose confidence. We lose confidence.

Page 8: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

What is anti-value?

Monolithic

Complex

Rigid

Tightly coupled

Fragile

Untested

Laden with technical debt

Page 9: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Value and Anti-value

Time

CostInitial

Release

Typical development lifecycle cost

Time

CostInitial

Release

Managing anti-value lifecycle cost

Page 10: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Simple, demonstrably correct code

Simple.

Demonstrably correct.

Page 11: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

What is complexity?

… Any code that can be decomposed into smaller components.

… Interrelationships and dependencies.

… The enemy of reliability.

… The part of our code that isn't beautiful.

… Code.

Page 12: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Why complexity is bad

We can't reason about our code.

We can't demonstrate our code is correct.

We can't trust our code.

Page 13: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

What is simplicity?

We can reason about our code.

We can demonstrate our code is correct.

We can trust our code.

Page 14: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

The simplicity test

Can I reason about this code?

Can I demonstrate that this code is correct?

Can I trust this code?

Page 15: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Code reviews

Do the tests cover the feature/issue fully?

Is the code under test easy to reason about?

Do I trust this code?

Page 16: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Evaluating tools

Can I reason about this code?

Can I demonstrate that this code is correct?

Can I trust this code?

Page 17: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

pure functions

Referential transparency

Immutability

Function composition

Laziness

Distribution

Functions are primitives

Page 18: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Functional-first programming

Simple mode

• First, code everything you can without side effects.

• Then, code your side effects.

Advanced mode

• First, code your side effects, and only your side effects.

• Then, code your business logic using pure functions.

Page 19: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Functional-first refactoring

1. Reproduce the issue manually.

2. Find the likely problem with the code.

3. Extract the business logic into a function, while leaving the side effects in the method.

4. Pass any arguments the function needs (purify).

5. Write a failing regression test around the function.

6. Write passing characterization tests around the function.

7. Fix the code to pass the regression test.

8. Refactor to reduce complexity and improve maintainability.

Page 20: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

There are two types of programming languages*

Some languages feel like they werebuilt in a garage

Some languages feel like they are based on the laws of the universe

* sarcasm provided at no extra charge

Page 21: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Functional programming languages

Referential transparency

Immutability

Function composition

Laziness

Distribution

Functions as primitives

Page 22: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Identity

In OOP, Identity is thecurrent state of the object.

In FP, Identity is acollection of states over time.

Page 23: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Databases

Relational databases

(Most) NoSQL databases

Immutable databases

What is a database anyway?

Page 24: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Reactive systems

Responsive

Resilient

Elastic

Event driven

Page 25: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Domain Driven Design

Domain

Model

Ubiquitous language

Entity

Event

Bounded context

Page 26: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

The front endPurpose

• Maximizing value for the user

• Creating the best experience

• Accomplishing the user’s goal

Business logic

• Purely functional

• Easy to test

Interface

• Event-driven

• Reactive

Page 27: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

The back endPurpose

• Protecting the integrity of the data by applying business logic

Business logic

• Purely functional

• Horizontal scaling

• Easy to test

Side effects

• Isolated

• Integration testing only

• Hexagonal

Page 28: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Solve for an architecture

Events go in

Events come out

Clients access domain services

Client applications solve different domain problems

Domain Services protect data integrity using business logic

System Of

Record

Domain Models are Projections

from Event Store

Page 29: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Domain events

Message bus or POST { [event data ] } TOhttp://[ eventstore ]/[ realm ]/[ domain ]/[ entity ID ]/[ event type ]

Persist to immutable CASSANDRA event store

Message bus or web sockets or GET { [event data ] } FROM http://[ eventstore ]/[ realm ]/[ domain ]/[ opt. entity ID ]/[ opt. event type ]

Page 30: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Domain services

Map events to functions

Apply the business logic

Maintain the domain model

Answer queries

Page 31: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Domain model

Projections

v.

Reductions

Page 32: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Distributed computing

Not invented here.

Page 33: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Simple, demonstrably correct systems (reactive version)

Focus on response

Reduce blast radius

Scale elastically

Pass messages asynchronously

Page 34: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Simple, demonstrably correct systems (Domain Driven Design version)

Architecture and business processes are isomorphic

We can talk to our business partners

Our business partners can comprehend our code

Domain events and services map to both ES-CQRS and Reactive

Does Eric Evans have an FP secret?

Page 35: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Simple, demonstrably correct systems (functional programming version)

The immutable event store

Events map to pure functions

Domain services are like a function applied to all our data

Eagerly, lazily

Isolated side effects

Pure functions, composed in a pipeline

Easy to reason about our whole system

Page 36: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Simple, demonstrably correct systems (summary version)

Can we reason about our system?

Can we demonstrate that our system is correct?

Can we trust our system?

Page 37: That's my monkey - lambdadays.org · That's my monkey A Functional, Reactive, Domain Driven Design, and Common Sense Approach To Architecture: This is my circus, and those are my

Rob Martin / version2beta

VP Engineering at BigSquid.com

Blogging at version2beta.com

@version2beta most everywhere online

Eventually, there will be an article version of this talk posted at version2beta.com/articles/thats_my_monkey/