Erlang Factory Lite Rome 2017 #1

Hello for the second (and last) part of EFL Rome2017 post! You can find previous one here

Music and Message Passing Concurrency by Joe Armstrong

Here goes the big name, Joe himself. While it may suggest a lot about music, it was more about messaging and integration. Joe showed how he could remotely control Sonic Pi. He was glad that there’s an other way to control a program “than clicking a bloody mouse!”.

He did that sending properly coded messages to UDP port. And here it all started. Joe is a big supporter of messaging based communication. API suposes a programming language, so it’s not a best way – you’re tied to programming language. As the main topic emerged once again – how to integrate and there are some programming languages better to do other things – so you’d naturally like to use them for specific purposes and not be stuck with one.

You should also treat specific parts/modules/apps like a black boxes – you know nothing (even the language used) except for how to communicate (using messages, of course 😉 ) – “the protocol only matters.”

  1. Pick transport (TCP/UDP)
  2. Pick encoding (XML/JSON/YAML/etc)
  3. Pick protocol description (RFC/UBF/etc)
Some combinations for you to pick from
With the Joe himself!

Joe picked OSC over TCP/UPD with some English to describe it. OSC is a very simple encoding – and it has “simplicity by design”, as Joe said, “if you can’t create complex data structures, the interface will be simple and easy to understand”.

“if you can’t create complex data structures, the interface will be simple and easy to understand”

Which is another way worth remebering. Complicated systems are easy – you just keep adding stuff. Simple systems are difficult to make.

I think thou – if one thing should be remembered from this talk it’s fact, that we should be able to understand the system by looking on the messages going in and out.

Adopting Elixir in a 10 Year Old Codebase by Michael Klishin

While it seems like adding Elixir to some Ruby ecosystem, it was actually using Elixir in Erlang project. They did a CLI tool in Elixir as a “check” with ~8k LOC, ~750 tests and 70 CL commands available.

I will just point out good:

  1. It’s more approachable than Erlang
  2. It’s a recriutment honeypot – easier to lure people into project
  3. Has decent standard lib
  4. Potentian contributors could have not contributed if it was in Erlang

And bad things he learned:

  1. Integration with is a pain
  2. Elixir/Erlang data type mismatches
  3. String vs Binary
  4. Some Elixir libs are a one man show ( 😉 )

Overall Michael feels like Elixir was worth adopting as sees a bright future for it – and you can utilize it even without agents, macros and sweet libs. He was even more optimistic for Elixir than for Erlang itself.

A Little Replica of the Internet in Elixir by Ju Liu

He describes himself as a Mad Scientist – and, boy, he is!

Basically it was a little trivia on the Internet and his attempt to do a small replica of it’s routing system using Elixir (and nerves). He had 2 RP3s connected, simulating North America and Europe with routing links. There’s a bit of how the Internet works and how it connects – he used that common knowledge to simulate it and it worked like a charm. There a code online if you want to look at it!

This is the Internet! Be careful not to break it!

The real show started when he took the router, connected third Rasp and added Asia – it all worked! It was a nice show for the Nerves project to show what you can do with them. Funny thing – the most problems, and the slowest part was HTML+JS frontend where all the arrows where hacked as separate CSS elements – so it crashed when connection number rose. Still, great project and you can look at it on github!

Embrace the Database with Ecto by Josh Branchaud

Basically it was how to use the Ecto and how to query the database. I really don’t know if it was the high temperature in the room, or it was just quite obvious to me – but I cannot say that I didn’t find anything at all – there was one statement that I won’t say if I find true or false – because it’s strengh is that it provokes some interesting conversations:

“The database should be the ultimate gatekeeper – it should validate the data coming in”

Monitoring and Pre-emptive support: The road to five nines on the Beam by Francesco Cesarini

It was a great talk with a lot of focusing on “no single point of failure” “we need at least 2 of everything”. He showed 2 types of monitoring usefulness – you can prevent failures, or do quick post-mortems. With monitoring you can prove your innocence in 1.5 minutes – without trying to replicate the bug and trying to debug. While there’s a lot to be said – he said so many cool stories I guess you have to go and give it a listen yourself – this one seems almost identical.

And this was it – it was a great experience and possibility to talk with those people was sometimes eye-opening.


As always – commit!

I really need to spend more time. Today I struggled a lot with bitstrings. And still didn’t find an answer for what I was looking for, but I created a map for command without redundant info. So no more flags, only command name, data and size.

After push thou I saw a better solution – I could do pattern match on functions, so I could eliminate switch. I get a lot of mess with all those maps. I think that rethinking/refactoring it should happen sooner than I initially thought.

Also “size” field seems a bit off. Additionally I don’t feel as comfortable enough with specification as I was expecting, so I guess I’ll spend some more time with it – this should also get me up to speed.

Erlang Factory Lite Rome 2017 #0

Week ago I went to Rome to take part in Erlang Factory Lite, and, as promised, here is blogpost about it (the first part)

Starting with venue – it was near the centre of the city, easy to get with decent views. While inside was quite small (not a lot of people were there as well), the outside…

What a place to take a break!


Sadly, there were no recordings, but from what I saw speakers had the same talks as in some future (and maybe past?) events, so not all is lost.

Pilgrim’s Progress to the Promised Land by Robert Virding

Opening talk by Erlang co-creator. It was a nice opening, showing learning Elixir as a pilgrimage. And it’s quite good analogy. You begin your journey influenced by some prophets. It’s important to validate their words – to decide if Elixir is the right tool for your job. Also the way of learning it is a bit like arriving to different interesting places.

Because of it’s similarity to Ruby you quickly arrive to “Village of Confusion” as things don’t seem to work they should. It’s not an OO language (Joe had different opinion here 😉 Erlang is the only OO language ).

Robert told us that people doing Erlang/Elixir are not scared of crashing things. And there are 3 ways of crashing things:

  1. Just crash
  2. Crash and clean – for example process holding database connection won’t close it if it dies
  3. Crash and restart – if process is critical to the system

Because of all this talking about crashing, you do a lot of upfront error handling – so you have it localized and easy.

“You have to accept that things go wrong it you want to build fault-tolerant systems” – Robert

Stepping into a new era: injecting Elixir in a Ruby app by Andrea Leopardi

This was the talk about replacing some parts of the existing Ruby + Python system with Elixir (and adding new ones with Elixir). This was quite full of examples (like issues going down significantly and performance going up), but I think that the most important thing is:

Prepare your system: Split it into services first, or at least one monolith service and one small (it’s a good start).

It’s the Type Theory Baby! by Michele Finelli

This was talk full with nice theory. Michele defined a formula something that is always true or false. If you depend on external (I/O, DB, etc) logical formulas are no longer eternal – so this describes functional programming.

Nice thingies:

  1. One thing to remember? Read this paper
  2. Basically wiki article around this talk
  3. Duck typing? No! It’s untyped and it’s fine!

Cook your distributed in memory KV store by Gianluca Padovani

Basically a explanation how Riak Core works with concrete idea to implement. It was with some demos how to make a distributed KV store. And it worked like charm 😉 I guess reading throu the code of this masterless cluster (nice idea btw) will be better than me describing it, but there one important quote

Always timeout!

I’ve covered 5 out of 9 talks, so there’s still material for next part, stay tuned!

Today I Learned #0

This is Today I Learned – some nice things I learned, too short to be valid blog post, but too important/interesting/etc to not be written down

While exposing classes to WCF service, you have to use [DataContract] (for class) and [DataMember] (for properties) attributes. Or do you?

Turns out that around 3.5 you don’t have to do it. If you provide class with no attributes it will work out of the box! Where’s the catch? There are two:

  1. You will lose some of features, like naming, being able to serialize private properties, declaring something as required. While some can be more useful than others in specific scenarios – just ask yourself – should you really send private data? 😉
  2. And this is important! If you dare to use [DataMember] on some properties – only those will be serialized.

OpenSettlersII #3

As always, commit to look at!

Today even smaller changes as I had little to no time, but at least moving slowly forward.

I added encoding of long frames. I did the same thing as in decoding, pattern match on flags and then construct proper binary data.

In tests file I added 2 tests for long frames and changed body: property in input to be binary as well. I think it’s starting to be a good time to introduce some struct for my frames, but I will worry about this later. I’m also not happy with return values – they should be more “elixiry”, so next step will be worrying about this (with some explanation what does it mean).

As I dislike post trailers – I’m going to Erlang Factory Lite tomorrow. I will try to write down as much as possible and make a interesting review next week, so stay tuned!

OpenSettlersII #2

Here’s a commit for you to look at!

I didn’t do much this week but progess is progress 🙂

I added the support for long frames. According documentation, long frame is defined by flag (Bit 1, “second one from right” must be 1). If the flag is set, size will be 8 octets, and body will be size octets. (So if size is 256, body will be 256 octets).

First lets look at tests. First change you can see is that I removed “reserved” from flags as it is not needed at all and obscured the data.
Next I renamed “command” key to “type” – as it reflects better what it is – it indicated the type of frame – if it is a command or message.
Next change (in decode) is that body is still in binary (inside << >>). I guess I will work on that later, but was needed in some changes.
I added 2 tests to correctly decode long frames, for both command and message. What’s important is :: size(64). It indicates the size of binary element. If not specified it will be default (8). What’s also important (and quite logical) size have to be divisible by 8.

Now onward to code itself. There’s only one public decode function, but it calls one of the private ones depending of the flag. There’s a pattern matching on long key, and binary data. As you can see here I used ::size accordingly.
What’s worth noting is if you want to match against unknown sized binary data you can use ::binary. Here I used it for body and for “rest” in main function – as before getting flags I don’t care about size and body.

And that’s it! Not a lot, but I learnt a bit when it comes to working with binary data in Elixir and made code a bit “better”.

RabbitMQ vs ZeroMQ

As for OpenSettlersII I want to present an interface to be able to implement for any possible GUI. And as I don’t want to tie anyone with Elixir/Erlang I decided to go with messages. I looked throu the net and my own experience, and there are two picks that I though I could use


RabbitMQ is a Your Typical Message Queue. There’s a message broker that handles messaging and whatnot. It’s written in Erlang, which is huge advantage, as I could use it directly from Elixir (you can call any Erlang function from Elixir with no obstacles). Not only that -there’s an official support for Elixir itself. I also used it in my previous work, as a client. It was trivial, as should be using it in OSII.

Or is it? My aim is to be able, after getting interface for GUI, to get started as quick as possible. With RabbitMQ, when you get to the server part, not only you have to install additional software, it can get ugly quickly. As for commercial products it’s not a problem, as there’s company with support behind it, for open source, pet project it is a problem.


I really need a citation here, but apparently creator of protocol for RabbitMQ decided that it’s not really that good and did ZMTP (ZeroMQ Message Transport Protocol). It is brokerless message queue and some may argue that it’s just simple socket. The biggest problem is message persistency – if you don’t have anything to hold/save messages while other party is offline – you’ll lost them. This doesn’t really sound like a problem to me, as I think that there are some mechanisms in OTP that can help me here.

ZeroMQ is really easy to configure, I worked a bit more with it and have fond memories with it. Basic communication worked out of the box, no need for any additional installations or configurations.


I decided to go with ZeroMQ for reasons stated above, but there’s one more reason. I may not google that much, but I haven’t seend any ZMTP 3.0/3.1 implementations made in Elixir. There are some bindings, sure. But nothing made out of scratch. I won’t lie – if I can learn even more doing this project and possibly make first 3.0/3.1 ZMTP for Elixir – I’m in!

Integration series: Messaging

Last time we spoke about some integration methods we can use.

As we see, there are methods that are not so tight coupled, being able to generate lots of little data packages (like file transfer), easily synchronizable (like shared database), details of storage’s structure hidden from applications (unlike shared database) and being able to send data to invoke behavior in other app (like RPI) but with being resistant to failure (unlike RPI).

And here messaging comes to play. The rules are simple: you create message, send it to message channel and someone waiting for this kind of message will get it. While it has some problems on it’s own, it is reliable, fequent, fast and asynchronous and.

  1. Being asynchronous means you won’t block process while waiting for the result/answer. Calling app can continue with it’s work.
  2. Decoupling. Messages will be sent to message channel without knowing almost anything about receiver. The common interface are the types of messages sent, not the bidings between apps. It also allows separation integration developement from application developement.
  3. Frequent, small messages allow applications to behave almost immediatly by sending more messages.

And many more we’ll explore in the series. Why I will write a series on it? The main disadvantage of messaging is the learning curve. While other methods are fairly easy to use, messaging and async thinking is not something we’re used to. But once learned this concepts will help you not only when integrating lots of enormous applications. You can also apply it to “integrate” classes/functions/actors in your code.

OpenSettlersII #1

Hello and welcome for a short update!

Here’s a commit to look at!

There’s not much and it’s not very nice code. But it’s something, right?

I decided to postpone Settlers II itself as I need transport layer. I decided ZMTP is the best one for me (why is the topic on the other blogpost incoming!) so I started doing something basic with it. According to ZMTP 3.1 specs first octet (8 bits) follows this convention:

  • bits 7-3 are reserved for future use and are 0
  • bit 2 indicates if frame is message (0) or command (1)
  • bit 1 indicates if frame is long(1) or short(0)
  • bit 0 indicates if there are more frames (1) after this one or not (0). For command it’s always 0.

Now for some clarification. “Bit 0” means “right-most bit”. Short message has body of 0 to 255 octets. Long message has body of 0 to 2^63 – 1 octets.

Next we have size field – it’s one or eight octets, depending on LONG flag. What’s important that size doesn’t include flags and itself – so empty frame has a size of 0 even if it has flags and size set.

Lastly we get SIZE octets of body.

In the commit we have simple encode/decode for frame with SIZE = 1, LONG = false. There’s a difference between Command and Message.

I am sure that “reserved” is redundant and code itself is not something clean and nice. But it’s a little start that I will continue working on and either refactor or throw it away.

Bytes are represented in Elixir as <<values>>. It’s quite useful to get working, but we can get better than I got here.

As for functional language specific stuff, please take a look at multiple definitions of private method decode_flags. It’s the pattern matching on functions (yup, can do it better here) – elixir will look for matching function and will call it. It’s simple and quite powerful feature.

In the next commit(s) and post I will make those encode/decode functions more general to be able to work on all sized frames. And hopefully more 😉

Introduction to integration

I started to get more into integration and integration patterns. There are few reasons:

  • Open Settlers II will be created with integration with possible UI integration in mind
  • It will be helpful in my daily job
  • I feel that it’s an important topic in software engineering

Having this set up, let’s briefly talk about some integration methods.

File transfer

We want two (or more) applications to exchange data. We can use simplest solution – write it to file for others to read. (Almost?) every language non-esoteric lanuage has some file read/write function built in. It is also easy to do no matter what environment you’re working with. Coupling is not so tight as application devs can (should?) agree on common file format(s) to work with. Changes in code won’t change the communication as long as output file is the same. With json it’s easier than ever. Even with third party apps it’s still trivial to consume messages from software we don’t have influence on.

There are also some downsides, too. There is a lot of work with deciding on file structure, file processing. Not too mention storage place, naming conventions, delivering file (if one app doesn’t have rights to output location of other), times of reading/writing (and what will happen if one reads while the other writes). But it all is nothing compared to one big problem. Changes propagate slowly (one system can produce file overnight, after “collection” of other). Desynchronization is common and it’s easy for corrupted data be spread before any validation (if it’s even possible).

Shared database

Shared database is a remedy for the synchronization problem. All data is in one central database, so information propagates instantly. Databases also have transaction mechanism to prevent some reading/writing-while-writing errors. You also don’t need to worry about different file formats.

But it also comes with a price. It’s difficult to design a shared database. Usually tables are designed to fit different applications and are a pain to work with. Worse if we’re talking enterprise level solutions and some critial app – its needs will be put higher, making work for others harder. After creating database design there’s a tendency to leave it as it is – changes can be hard to follow. Another problem is third-party software. It will usually work with its own design and it may change with newer verions. Database itself can become a perfomance bottleneck

Remote Procedure Invocation

Sometimes sharing data is not enough, because data changes may require actions in different applications. Think changing address at goverment service – there are a lot of adustments and documents to be generated. Apps maintain integrity of data it owns. It also can modify it without affecting other appliactions. Multiple interfaces to CRUD data can be created (e.g. few methods to update data, depending on caller), which can prevent semantic dissonance and enforces encapsulation.

It may loosen the coupling, but it’s still quite tight. In particular doing things in particular order can lead to muddy mess. While developers know how to write procedures (it’s what we do all the time, right?) and it may seem like a good thing it’s actually not so good. It’s easy to forget that we’re not calling local procedure and that it will take more time or can fail due to multiple reasons. Due to this thinking also quite tight coupling arises (as stated before).

As always, there’s always a tradeoff. But do we have the best approach here? Or can we do even better? I’ll address these questions in the next post in series.