際際滷

際際滷Share a Scribd company logo
Software
Architecture
using MQ

by
Pieter Hintjens
Strange Loop 2012
Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
A complex
story is best
told as a
series of
vacuous 1-
liners



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
90% of
software is
trash.

90% of the
rest will be
trash RSN


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
We basically
don't know
how to
make code
that can
survive ten,
let alone 50
years

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
The most
difficult
challenge
in our
profession
is simple
accuracy


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Future code
has to talk
to code, has
to be chatty,
sociable,
well-
connected


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
When we
can move
faster,
where we
go is more
critical than
ever.


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Writing
distributed
code is like
a live jam
session.

It's all about
other people

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
How we
connect to
each other
matters
more than
who we are



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
The physics
of software
is the
physics of
people




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Ideas are
cheap.

Execution is
the hard
part



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Making
perfect
software is
easy, once
you learn
the trick
(which is
kinda hard)

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Simplicity
always
beats
functionality




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Problems
are not all
equal, and
most are
illusions




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
When you
know the
real problem
you have
done half
the work



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Do nothing
that is not a
minimal,
plausible
answer to a
well-defined
problem


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Every
commit
should be
shippable




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Design by
removing
problems,
not adding
features




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Five Steps
to Satori:
Learn,
Draw,
Divide,
Conquer,
Repeat


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
1.
Learn the
language
before you
write a
poem



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
2.
If it looks
pretty, it's
more likely
to work




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
3.
A good
contract is
worth a
thousands
assumptions



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
4.
When you
take small
steps, it
hurts less
when you
fall


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
5.
Solve one
problem,
and repeat
until you run
out of time
or money


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Distributed
software
lives or dies
by its
protocols




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Protocols
are contracts
that describe
the rights
and
obligations
of each party


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
An unprotocol
takes minutes
to explain,
hours to
design, days to
write, weeks to
prove, months
to mature, and
years to
replace
Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Use human                         nom-protocol =
                                     open-peering
language                            *use-peering
in your                           open-peering =
unprotocols.                         C:OHAI
                                   ( S:OHAI-OK / S:WTF )

                                  use-peering =
ORLY?                                C:ICANHAZ
YARLY!                             / S:CHEEZBURGER
                                   / C:HUGZ S:HUGZ-OK
                                   / S:HUGZ C:HUGZ-OK


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Use GPLv3
for your
open specs.

Remixability
is freedom



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
If you're
willing to
give up
flexibility for
speed you
deserve
neither
flexibility nor
speed
Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Use cheap
text for the
low-volume
chatty
control
commands



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Use nasty
hand-coded
binary for
the high-
volume data




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
MQ
framing
makes a
lousy codec
but a great
separator



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
A hand-
crafted
codec can
always beat
a generic
serializer



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
A code-
generated
codec can
always beat
a hand-
crafted one



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
iMatix GSL:
technology
so dangerous
we had to
lock it up for
years



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
File transfer
is the
zombie
problem of
distributed
applications



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Router
sockets are
the beating
heart of
every real
MQ
protocol
engine

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
The world
needs a
chunked,
flow-controlled,
restartable,
cancellable,
async,
multicast
file transfer
MQ protocol

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
No matter                         C:   fetch
how hard                          S:   chunk 1
you push, a                       S:   chunk 2
file will not                     S:   chunk 3
just go down
a socket



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
That                              C:   fetch chunk 1
annoying                          S:   send chunk 1
pause after                       C:   fetch chunk 2
                                  S:   send chunk 2
you finish
                                  C:   fetch chunk 3
your beer,                        S:   send chunk 3
before you                        C:   fetch chunk 4
catch the
waiter's eye

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
You can,                          C:   fetch chunk 1
and I've                          C:   fetch chunk 2
tested this,                      C:   fetch chunk 3
                                  S:   send chunk 1
order a new
                                  C:   fetch chunk 4
beer before                       S:   send chunk 2
your old one                      S:   send chunk 3
is empty


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Request-                          C:   subscribe
reply is just                     C:   send credit
a vulgar                          S:   send chunk
                                  S:   send chunk
subclass of
                                  C:   send credit
publish-                          S:   send chunk
subscribe



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
On a router
socket, you
should
never hit the
high-water
mark



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Heartbeats
are our
protocol's
way of
asking if we
still care



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Protocol                          command_t
stack                              *request =
=                                 command_decode
                                   (socket)
message
codec                             execute_engine
+                                  (command)
protocol
engine

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
State
machines
are a perfect
domain
language for
protocol
engines


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
State
machines
can be cudly
and gentle,
when you
get to know
them


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
You don't
want to bet
against a
compiler




Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
If you're not
thinking of
security,
security is
probably
thinking of
you


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
For
connected
bidirectional
protocols
over MQ
use SASL



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
For loosely
connected
and one-way
protocols
over MQ,
use AES and
such


Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
secure-nom = open-peering
SASL over                                     *use-peering

MQ is                            open-peering =
                                      C:OHAI
darned                             *( S:ORLY C:YARLY )
simple                              ( S:OHAI-OK / S:WTF )

                                  ORLY = 1*mechanism
                                         challenge
                                  mechanism = string
                                  challenge = *OCTET

                                  YARLY = mechanism
                                          response
                                  response = *OCTET

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
Theory is
fine in
theory, but
in practice,
practice is
better



Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
FileMQ is a
file sharing
protocol and
stack over
MQ.

Reusable
until 2062

Photos by Pieter Hintjens
cc-by-sa 息 2012 Pieter Hintjens
1. Aim for 50 years
To sum it up:                     2. It's all about people
                                  3. Minimal plausible solutions
zero.mq/ch6                       4. To real immediate problems
                                  5. Document the contracts
                                  6. Cheap and Nasty codecs
The Weird                         7. Code generation rocks
Fish Book,                        8. Router sockets rock
coming soon                       9. CBFC > HWM
from O'Reilly                     10. Learn state machines
                                  11. Learn about SASL

Photos by Pieter Hintjens
                                  12. Worked example: FileMQ
cc-by-sa 息 2012 Pieter Hintjens

More Related Content

Software Architecture over ZeroMQ