@GanbaroDigital
“
We can chop and change the modules -
and their order -
without having to touch
the modules themselves
Slide 27
Slide 27 text
@GanbaroDigital
The pipeline itself
is defined in config, not code.
Slide 28
Slide 28 text
@GanbaroDigital
Slide 29
Slide 29 text
@GanbaroDigital
??
??
What Happens To
The Data?
Slide 30
Slide 30 text
@GanbaroDigital
Data In A Pipeline Can Be …
1. modified
2. transformed
3. or rejected
Slide 31
Slide 31 text
@GanbaroDigital
Data In A Pipeline Can Be …
1. modified
2. transformed
3. or rejected
Slide 32
Slide 32 text
@GanbaroDigital
Data In A Pipeline Can Be …
1. modified
2. transformed
3. or rejected
Slide 33
Slide 33 text
@GanbaroDigital
PSR7 Middleware
is a data transformation pipeline:
It turns HTTP requests
into HTTP responses.
Slide 34
Slide 34 text
@GanbaroDigital
Building A Pipeline
Slide 35
Slide 35 text
@GanbaroDigital
Real-life use case:
messaging in the #cloud
Slide 36
Slide 36 text
@GanbaroDigital
Back Office
Service
Public
Web App
API
Slide 37
Slide 37 text
@GanbaroDigital
Back Office
Service
Public
Web App
API
Status Events
Slide 38
Slide 38 text
@GanbaroDigital
Back Office
Service
Public
Web App
API
Status Events
Message Queue
Slide 39
Slide 39 text
@GanbaroDigital
Design Constraints
1. We must use the cloud-provider’s message
queueing service
2. Different programming languages in use for
transmitting and receiving systems
Slide 40
Slide 40 text
@GanbaroDigital
Principle:
Always treat
the cloud-provider’s infrastructure
as an untrusted third-party system.
Slide 41
Slide 41 text
@GanbaroDigital
Traffic to and from
the message queue
goes over HTTPS.
The messages are encrypted
on the wire / in transit.
Slide 42
Slide 42 text
@GanbaroDigital
Messages at rest
inside the queue?
Not guaranteed
to be encrypted.
Slide 43
Slide 43 text
@GanbaroDigital
Encrypt
Slide 44
Slide 44 text
@GanbaroDigital
Encrypt
HMAC
Slide 45
Slide 45 text
@GanbaroDigital
The message queue
does not accept
arbitrary binary data.
Only 7-bit ASCII.
Their castle, their rules.
Slide 46
Slide 46 text
@GanbaroDigital
Encrypt
HMAC
Slide 47
Slide 47 text
@GanbaroDigital
Encrypt
HMAC
Ascii-Safe
Slide 48
Slide 48 text
@GanbaroDigital
Design Constraints
1. We must use the cloud-provider’s message
queueing service
2. Different programming languages in use for
transmitting and receiving systems
Slide 49
Slide 49 text
@GanbaroDigital
Encrypt
HMAC
Ascii-Safe
Slide 50
Slide 50 text
@GanbaroDigital
JSON
Encrypt
HMAC
Ascii-Safe
Slide 51
Slide 51 text
@GanbaroDigital
In real life,
the requirements to encrypt
came late in the day.
Slide 52
Slide 52 text
@GanbaroDigital
JSON
Ascii-Safe
Slide 53
Slide 53 text
@GanbaroDigital
Because We Built A Pipeline
• Created new modules
• Dropped them in where we needed them
• Zero changes to signed-off code
Slide 54
Slide 54 text
@GanbaroDigital
JSON
Ascii-Safe
Encrypt
HMAC
Slide 55
Slide 55 text
@GanbaroDigital
JSON
Encrypt
HMAC
Ascii-Safe
Slide 56
Slide 56 text
@GanbaroDigital
Because We Built A Pipeline
• Created new modules
• Dropped them in where we needed them
• Zero changes to signed-off code
• Reduced impact on deployment pipeline
Slide 57
Slide 57 text
@GanbaroDigital
Requirements drive
the design of your pipelines.
Slide 58
Slide 58 text
@GanbaroDigital
Let’s break down
how to implement
your requirements.
Slide 59
Slide 59 text
@GanbaroDigital
JSON
Encrypt
HMAC
Ascii-Safe
Slide 60
Slide 60 text
@GanbaroDigital
JSON
Encrypt
HMAC
Ascii-Safe
Not the code that runs
inside the pipeline!
@GanbaroDigital
NextInstruction
also enforces type safety.
It’s unique to your library.
Only Instructions written for your library
will accept your NextInstruction.
Slide 185
Slide 185 text
@GanbaroDigital
Slide 186
Slide 186 text
@GanbaroDigital
??
??
Did you notice
the runtime checks
that we still needed?
Slide 187
Slide 187 text
@GanbaroDigital
Slide 188
Slide 188 text
@GanbaroDigital
Strict typing is
the equivalent of ‘filters’
from ‘input filtering and validation’.
Strict typing doesn’t cover
your data validation responsibilities.
Slide 189
Slide 189 text
@GanbaroDigital
You still need appropriate
runtime checks.
You still need appropriate
unit tests.
Slide 190
Slide 190 text
@GanbaroDigital
Testing
Slide 191
Slide 191 text
@GanbaroDigital
Instruction Pipelines
are easy to test.
Slide 192
Slide 192 text
@GanbaroDigital
Unit Test Build Order
1. Operations
2. Instructions
3. NextInstruction & build helper
Slide 193
Slide 193 text
@GanbaroDigital
Operations are plain PHP,
by design.
There’s nothing special
required to test them.
Slide 194
Slide 194 text
@GanbaroDigital
Slide 195
Slide 195 text
@GanbaroDigital
Unit Test Build Order
1. Operations
2. Instructions
3. NextInstruction & build helper
Slide 196
Slide 196 text
@GanbaroDigital
Slide 197
Slide 197 text
@GanbaroDigital
Unit Test Build Order
1. Operations
2. Instructions
3. NextInstruction & build helper
Slide 198
Slide 198 text
@GanbaroDigital
They have single responsibilities.
We don’t need many tests
to prove that they work.
Slide 199
Slide 199 text
@GanbaroDigital
Slide 200
Slide 200 text
@GanbaroDigital
Slide 201
Slide 201 text
@GanbaroDigital
Slide 202
Slide 202 text
@GanbaroDigital
“With 100% code coverage,
you could still ship bugs.
Without 100% code coverage,
you’re definitely shipping bugs.
Slide 203
Slide 203 text
@GanbaroDigital
Full code available
on GitHub & Packagist:
ganbarodigital/
php-mv-messaging-pipeline
Slide 204
Slide 204 text
Thank You
Any Questions?
A presentation by @stuherbert
for @GanbaroDigital