Software Architecture over ZeroMQ

56
Photos by Pieter Hintjens cc-by-sa © 2012 Pieter Hintjens Software Architecture using ØMQ by Pieter Hintjens Strange Loop 2012

description

Presented at Strange Loop 2012 How to build large systems that can survive 50 years.

Transcript of Software Architecture over ZeroMQ

Page 1: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

SoftwareArchitectureusing ØMQ

byPieter HintjensStrange Loop 2012

Page 2: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

A complex story is best told as a series of vacuous 1-liners

Page 3: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

90% of software is trash.

90% of the rest will be trash RSN

Page 4: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

We basically don't know how to make code that can survive ten, let alone 50 years

Page 5: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

The most difficult challenge in our profession is simple accuracy

Page 6: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Future code has to talk to code, has to be chatty, sociable, well-connected

Page 7: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

When we can move faster, where we go is more critical than ever.

Page 8: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Writing distributed code is like a live jam session.

It's all about other people

Page 9: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

How we connect to each other matters more than who we are

Page 10: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

The physics of software is the physics of people

Page 11: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Ideas are cheap.

Execution is the hard part

Page 12: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Making perfect software is easy, once you learn the trick (which is kinda hard)

Page 13: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Simplicity always beats functionality

Page 14: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Problems are not all equal, and most are illusions

Page 15: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

When you know the real problem you have done half the work

Page 16: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Do nothing that is not a minimal, plausible answer to a well-defined problem

Page 17: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Every commit should be shippable

Page 18: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Design by removing problems, not adding features

Page 19: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Five Steps to Satori: Learn, Draw, Divide, Conquer, Repeat

Page 20: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

1. Learn the language before you write a poem

Page 21: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

2.If it looks pretty, it's more likely to work

Page 22: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

3.A good contract is worth a thousands assumptions

Page 23: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

4.When you take small steps, it hurts less when you fall

Page 24: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

5.Solve one problem, and repeat until you run out of time or money

Page 25: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Distributed software lives or dies by its protocols

Page 26: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Protocols are contracts that describe the rights and obligations of each party

Page 27: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-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

Page 28: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Use human languagein your unprotocols.

ORLY? YARLY!

nom-protocol = open-peering *use-peering

open-peering = C:OHAI ( S:OHAI-OK / S:WTF )

use-peering = C:ICANHAZ / S:CHEEZBURGER / C:HUGZ S:HUGZ-OK / S:HUGZ C:HUGZ-OK

Page 29: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Use GPLv3 for your open specs.

Remixability is freedom

Page 30: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

If you're willing to give up flexibility for speed you deserve neither flexibility nor speed

Page 31: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Use cheap text for thelow-volume chatty control commands

Page 32: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Use nasty hand-coded binary for the high-volume data

Page 33: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

ØMQ framing makes a lousy codec but a great separator

Page 34: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

A hand-crafted codec can always beat a generic serializer

Page 35: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

A code-generated codec can always beat a hand-crafted one

Page 36: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

iMatix GSL: technology so dangerous we had to lock it up for years

Page 37: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

File transfer is the zombie problem of distributed applications

Page 38: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Router sockets are the beating heart of every real ØMQ protocol engine

Page 39: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

The world needs a chunked, flow-controlled, restartable, cancellable, async, multicast file transfer ØMQ protocol

Page 40: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

No matter how hard you push, a file will not just go down a socket

C: fetchS: chunk 1S: chunk 2S: chunk 3

Page 41: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

That annoying pause after you finish your beer, before you catch the waiter's eye

C: fetch chunk 1S: send chunk 1C: fetch chunk 2S: send chunk 2C: fetch chunk 3S: send chunk 3C: fetch chunk 4

Page 42: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

You can, and I've tested this, order a new beer before your old one is empty

C: fetch chunk 1C: fetch chunk 2C: fetch chunk 3S: send chunk 1C: fetch chunk 4S: send chunk 2S: send chunk 3

Page 43: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Request-reply is just a vulgar subclass of publish-subscribe

C: subscribeC: send creditS: send chunkS: send chunkC: send creditS: send chunk

Page 44: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

On a router socket, you should never hit the high-water mark

Page 45: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Heartbeats are our protocol's way of asking if we still care

Page 46: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Protocol stack = message codec +protocol engine

command_t *request = command_decode (socket)

execute_engine (command)

Page 47: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

State machines are a perfect domain language for protocol engines

Page 48: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

State machines can be cudly and gentle, when you get to know them

Page 49: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

You don't want to bet against a compiler

Page 50: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

If you're not thinking of security, security is probably thinking of you

Page 51: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

For connected bidirectional protocols over ØMQ use SASL

Page 52: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

For loosely connected and one-way protocols over ØMQ, use AES and such

Page 53: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

SASL over ØMQ is darned simple

secure-nom = open-peering *use-peering

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

ORLY = 1*mechanism challengemechanism = stringchallenge = *OCTET

YARLY = mechanism responseresponse = *OCTET

Page 54: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

Theory is fine in theory, but in practice, practice is better

Page 55: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

FileMQ is a file sharing protocol and stack over ØMQ.

Reusable until 2062

Page 56: Software Architecture over ZeroMQ

Photos by Pieter Hintjenscc-by-sa © 2012 Pieter Hintjens

To sum it up:

zero.mq/ch6

The Weird Fish Book, coming soon from O'Reilly

1. Aim for 50 years

2. It's all about people

3. Minimal plausible solutions

4. To real immediate problems

5. Document the contracts

6. Cheap and Nasty codecs

7. Code generation rocks

8. Router sockets rock

9. CBFC > HWM

10. Learn state machines

11. Learn about SASL

12. Worked example: FileMQ