News for hackers. Stuff that matters.
Re:Give Me Back My Monolith by bunderbunder on Thursday March 14, 2019 @12:07AM (#19386458)
The first thing I start trying to convince people to ditch on any internal service is JSON.

There are only two times when JSON is a particularly good choice: when it's important for the messages themselves to be human-readable, or when it's important to be able to consume it from JavaScript without using a library. Any other time, something like protocol buffers is going to give you lower latency, lower bandwidth requirements, lower CPU costs, lower development effort, less need for maintaining documentation, and better standardization.

If you ditch the HTTP stuff while you're at it, you can also handily circumvent all the ambiguities and inter-developer holy wars that are all but inherent to the process of taking your service's semantics, whatever they are, and trying to shoehorn them into a 30-year-old protocol that was really only meant to be used for transferring hypermedia documents. Instead you get to design your own protocol that meets your own needs. Which, if you're already building on top of something like protobuf, will probably end up being a much simpler and easier-to-use protocol than HTTP.

Re:Give Me Back My Monolith by stouset on Thursday March 14, 2019 @02:52AM (#19387008)
Not to mention, JSON APIs start out simple because you just call `to_json` on whatever object you need to share and then move on. Except nobody’s ever documented the format, and handling ends up taking place in a million different places because you can just pass the relevant bits around. The API is “whatever it did before we split it up”.

Now when someone goes to replace one side, it’s often impossible to even figure out a full definition of the structure of the data, much less the semantics. You watch a handful of data come across the pipe, build a replacement that handles everything you’ve seen, and then spend the next few months playing whack-a-mole fixing bugs when data doesn’t conform to your structural or semantic expectations.

JSON lets you get away with never really specifying your APIs, and your APIs often devolve to garbage by default. Then it becomes wildly difficult to ever replace any of the parts. JSON for internal service APIs is unmitigated evil.

Re:Give Me Back My Monolith by humbleMouse on Thursday March 14, 2019 @10:15AM (#19389369)
You could just make a shared object module that is versioned and have all the microservices use those objects to communicate. Or you could implement avro schemas. Many ways around this issue.
Re:Give Me Back My Monolith by jypepin on Thursday March 14, 2019 @06:25AM (#19387918)
I don't know if I would recommend NOT using json when starting out (I'm on the side of pushing for a monolith for as long as possible), but yes omg I've been there.

I've migrated multiple services out of our monolith into our micro service architecture and oh boy, it is just impossible to know (or find someone who knows) what structure is passed around, or what key is actually being used or not. Good luck logging everything and pulling your hair documenting everything from the bottom up.

Re:Give Me Back My Monolith by geezerjay on Thursday March 14, 2019 @04:50AM (#19387491)
> Except nobody’s ever documented the format,

That's hardly a JSON problem. You still experience that problem if you adopt any undocumented document format or schema.

Re:Give Me Back My Monolith by danmaz74 on Thursday March 14, 2019 @05:52AM (#19387751)
I think the point the OP was making was more about the tooling than the format. Having a library that forces you to define the format you're using, instead of dumping to_json whatever internal representation you had, also doubles as documentation.

But then, of course, that can be considered boilerplate code (and, in the beginning and most of the time, it actually is just a duplication of your internal object structure).

Re:Give Me Back My Monolith by bunderbunder on Thursday March 14, 2019 @09:47AM (#19389150)
That, and having the format definition file support comments means that you have a convenient all-in-one place where, at lest in the more straightforward cases, you can handily describe both the message format and the service's behavior in a single file that's easy to share among all your teams.
Re:Give Me Back My Monolith by stouset on Thursday March 14, 2019 @12:09PM (#19390561)
Precisely.

The easiest path with JSON is to do none of this, and so the majority of teams (particularly inexperienced ones) do none of it. With protos, someone must at least sit down and authoritatively outline the structure of any data being passed around, so at a minimum you’ll have that.

But even just forcing developers to do this generally means they start thinking about the API, and have a much higher chance of documenting the semantics and cleaning up parts that might otherwise have been unclear, confusing, or overly complex.

Re:Give Me Back My Monolith by mruts on Thursday March 14, 2019 @05:53AM (#19387756)
I’m surprised that bencoded dictionaries haven’t ever become popular outside of bittorrent. They are expressive, fast, and easy to implement.
Re:Give Me Back My Monolith by CoolGuySteve on Thursday March 14, 2019 @01:54AM (#19386810)
Man if you think protobuf is fast, just wait until you try C pod structs with type-length headers.

They are literally infinitely faster to encode/decode than protobuf.

They even have the same obnoxious append-only extensibility of protobuf if that’s what really gets your jimmies firing.

Re:Give Me Back My Monolith by Danieru on Thursday March 14, 2019 @02:49AM (#19386996)
FlatBuffers and then Endian concerns are gone.
Re:Give Me Back My Monolith by presscast on Thursday March 14, 2019 @06:17AM (#19387875)
Are FlatBuffers essentially Capnproto without the RPC?
Re:Give Me Back My Monolith by alexhutcheson on Thursday March 14, 2019 @11:08AM (#19389883)
FlatBuffers can be used with gRPC, so they shouldn't need a separate RPC ecosystem like Cap'n Proto: https://grpc.io/blog/flatbuffers
Re:Give Me Back My Monolith by presscast on Thursday March 14, 2019 @12:07PM (#19390542)
Right, but I'm asking if FlatBuffers' approach to encoding is similar to Cap'n Proto. It seems like the answer is "yes", but I might be missing something.
Re:Give Me Back My Monolith by kentonv on Thursday March 14, 2019 @12:15PM (#19390628)
They are both zero-copy, but the designs have a number of differences. I compared them back in 2014: https://capnproto.org/news/2014-06-17-capnproto-flatbuffers-...

Disclaimers:

1) I'm the author of Cap'n Proto; I'm probably biased.

2) A lot could have changed since 2014. (Though, obviously, serialization formats need to be backwards-compatible which limits the amount they can change...)

Re:Give Me Back My Monolith by presscast on Thursday March 14, 2019 @12:20PM (#19390687)
Cool, thanks for this! I'm happily using Cap'n Proto in a side project, and so far have really enjoyed working with it. It's a really impressive piece of engineering.
Re:Give Me Back My Monolith by netmonk on Thursday March 14, 2019 @01:57AM (#19386818)
asn1 for the win
Re:Give Me Back My Monolith by carapace on Thursday March 14, 2019 @01:53PM (#19391652)
It's a shame you're catching downvotes for mentioning ASN1. It's so much better than all these newfangled things that it makes them look like toys.
Re:Give Me Back My Monolith by rkeene2 on Saturday March 16, 2019 @03:57PM (#19409853)
I'm not sure why ASN.1 isn't more popular for a zero-copy encoding system
Re:Give Me Back My Monolith by StavrosK on Thursday March 14, 2019 @07:25AM (#19388229)
What serialization format do you all recommend when starting out? Protobufs seems to be the go-to, but what about Cap'n Proto etc?
Re:Give Me Back My Monolith by alexhutcheson on Thursday March 14, 2019 @10:57AM (#19389778)
(personal opinion, not speaking on behalf of my employer)

Start out with protobufs, so you can take advantage of gRPC[1] and all of its libraries and all the other tooling that is out there.

If you profile and determine that serialization/deserialization is actually a bottleneck in your system in a way that is product-relevant or has non-trivial resource costs, then you can look at migrating to FlatBuffers, which can still use gRPC[2].

[1] https://grpc.io/ [2] https://grpc.io/blog/flatbuffers

Re:Give Me Back My Monolith by StavrosK on Thursday March 14, 2019 @11:07AM (#19389872)
Ah, good tip, thanks!
Re:Give Me Back My Monolith by bunderbunder on Thursday March 14, 2019 @12:15PM (#19390626)
I'd agree on starting with protobufs, precisely because it's the go-to. Other options have plenty of advantages, but none are as widely supported.