News for hackers. Stuff that matters.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by maltalex on Sunday December 10, 2017 @06:58AM (#15891057)
JSON loses its appeal once you're not targeting browsers and/or anything else that uses Javascript. Sure, it's simple and familiar, but it has serious drawbacks such as the time and CPU resources it takes for parsing and the lack of schema.

For those of you interested, I suggest using Google's protobufs or even full blown gRPC for such endeavors.

See discussion about gRPC here: https://news.ycombinator.com/item?id=12344995

Protobufs: https://developers.google.com/protocol-buffers/

Re:Son: A minimal subset of JSON for machine-to-machine comm... by onion2k on Sunday December 10, 2017 @08:36AM (#15891304)
Sure, it's simple and familiar, but it has serious drawbacks such as the time and CPU resources it takes for parsing and the lack of schema.

Before looking for something 'better' than JSON, build a basic prototype of your app and see if your application actually needs to use something else. The data in most applications is so small and will parse so easily that actually measuring the CPU utilisation will be quite hard. 99.99% of applications aren't moving data around at the sort of speed where the format really matters.

Protocol buffers are very clever and really cool but using them where you don't need them is a huge waste of effort.

As for the lack of a schema that's not true. There is a schema. What's in the file is defined somewhere. For applications that consume JSON that's in your code rather than the file format.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by lobster_johnson on Sunday December 10, 2017 @11:08AM (#15891988)
JSON will easily dominate CPU usage in any modern application that uses it for its API (and is not itself something intrinsically CPU-hungry like crypto or machine learning).

We benchmarked one of our apps, written in Go, which uses JSON extensively both for the API and for internal storage, and we found that around 90% of the CPU time is spent serializing and deserializing JSON.

The JSON code itself is a tiny portion of any app, so it's one of those rare optimization cases where a small change can yield significant speed-ups for the entire app.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by megous on Sunday December 10, 2017 @02:07PM (#15892921)
Depends on the way you handle JSON. You don't need to deserialize the entire received JSON string and then walk the node tree, you can walk the string as is. With this, you can process 500MB/s or more of JSON on a single core.

On the other side, you can produce JSON string directly, saving the need to produce some intermediate representation in memory.

You should be able to saturate 10gbit line on a multicore server easilly with this approach.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by foobarbazetc on Sunday December 10, 2017 @02:01PM (#15892893)
Our Scala based servers handling thousands of RPS only deal with JSON via Jackson and JSON encode/decode doesn’t even register in profiles.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by akvadrako on Monday December 11, 2017 @05:23AM (#15896175)
Agreed; in data-centric apps the JSON parsing time is a major time suck. But sometimes it can be heavily optimised with a good library, like fastjson for Java.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by always_good on Sunday December 10, 2017 @01:36PM (#15892748)
Was it a JSON echo server?
Re:Son: A minimal subset of JSON for machine-to-machine comm... by nitrogen on Sunday December 10, 2017 @02:21PM (#15892991)
There are formats that fall between unrestricted JSON and strict predefined schemas like Protobufs or Thrift. I have used MessagePack for internal APIs and message queues where JSON was too slow but we still wanted a self-describing format. You can decode msgpack for debugging without needing the original definition (there is none), unlike a fixed schema format.

No affiliation, just satisfied user.

http://msgpack.org/index.html

Re:Son: A minimal subset of JSON for machine-to-machine comm... by maltalex on Sunday December 10, 2017 @11:18AM (#15892037)
> Before looking for something 'better' than JSON, build a basic prototype of your app and see if your application actually needs to use something else.

That implies that JSON is somehow the gold standard of serialization formats. I don't see it that way. The fact that JSON is ubiquitous in some areas doesn't mean that it's the gold standard for all other uses.

In my experience, protobufs are easy to work with, concise, safe, and efficient. There's never any ambiguity to them, and both creating and parsing messages is fast and easy. That doesn't mean that there aren't cases in which JSONs aren't a better choice, for instance when working with browsers, or needing a text based format for debugging or inspection purposes.

> Protocol buffers are very clever and really cool but using them where you don't need them is a huge waste of effort.

In my experience protobufs require very little effort, with most of the effort being put into defining the schema. It's pretty frictionless afterwards with one notable exception - when you want to manually inspect a message. That's where JSON wins hands down.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by onion2k on Sunday December 10, 2017 @02:30PM (#15893049)
That implies that JSON is somehow the gold standard of serialization formats.

I'm not suggesting JSON is the best format, because that depends on the project you're working on. I'm saying it's good enough for most tasks, and has ubituous support, and it's easy to work with. There are better formats for particular use cases but if your application has requirements that can work with JSON it probably isn't worth finding something else.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by skybrian on Sunday December 10, 2017 @04:34PM (#15893612)
Protobufs do require more effort in the toolchain. Pretty much the only way to parse a .proto file is with protoc and you might need to build it from source. So you need to run the C++ compiler and depending in the build system you're using, adding a dependency on protoc at build time can be a pain.

Contrast with JSON where every decent language ecosystem has a parser readily available. That's what makes it the "gold standard" for me.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by cdancette on Sunday December 10, 2017 @12:18PM (#15892333)
Protobuf seems more complicated to debug manually.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by falcolas on Sunday December 10, 2017 @09:35AM (#15891531)
Protobuffers have one major advantage over JSON: the schemas are versioned. When your requirements for the payload inevitably change, Protobuffers can handle that with a lot less muss and fuss than JSON can.

Plus, the byte count over the wire is much smaller - something that matters even in today's world of gigabit ethernet.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by ninjakeyboard on Sunday December 10, 2017 @10:02AM (#15891662)
You have to compile the protocol buffers so there is overhead. Also the messages aren't human readable eg through kafka so you need to write something to look through the messages. JSON is faster if your dev team need to get from A to B in a hurry, but protocol buffers are a generally a better long term choice if you can put in the effort up front. Both have pros and cons.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by pegasuscollins on Sunday December 10, 2017 @10:27AM (#15891787)
> Protobuffers can handle that with a lot less muss and fuss than JSON can.

Are you speaking from personal experience? FWIW it doesn't match mine.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by skybrian on Sunday December 10, 2017 @04:45PM (#15893660)
Not sure what you mean by "schemas are versioned". Protobufs have backward compatibility rules so you can add fields without changing versions. I don't think there's anything about explicit versioning in the spec?
Re:Son: A minimal subset of JSON for machine-to-machine comm... by ansgri on Sunday December 10, 2017 @07:29AM (#15891125)
JSON, like XML, is supported by everything, including not only general purpose languages, but also by more specialized environments like MATLAB. Also its compatibility across implementations is very good, excluding support for comments and nonfinite numbers. Contrary to YAML, I mean; there's little reason to use XML except for legacy or markup purposes.

JSON-schema implementations are also rather widely available.

In performance-sensitive machine-to-machine applications, I agree, better to use someting compiled, but for general-purpose interoperation and archive data storage (where you cannot know when and with what tool you'll want to open it), I've yet to see a compelling alternative.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by Derbasti on Sunday December 10, 2017 @07:58AM (#15891205)
To be fair, MATLAB only added support for reading/writing JSON this very year. And they represent JSON objects as structs, which don't support all key names, and they have a very "idiomatic" idea of which JSON arrays are decoded as matrices or cells, and how nested arrays sometimes result in nested arrays, and sometimes result in multi-dimensional arrays. And there's an uneasy relationship between the empty array and Null. It is kind of a mess, really.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by radarsat1 on Sunday December 10, 2017 @09:39AM (#15891546)
Also to be fair, although I can see some uses for supporting JSON in MATLAB, it makes a lot more sense if you're using an array language to use an array-oriented format such as HDF5, which has been supported in all the major numerical platforms for quite a while.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by sundarurfriend on Sunday December 10, 2017 @12:27PM (#15892385)
> It is kind of a mess, really.

Honestly, that statement applies to pretty much any part of MATLAB unless the behaviour is nailed down by existing mathematical or engineering specifications - and I'm talking as someone that likes MATLAB overall. Mathworks tries a bit to polish and paint it as a coherent whole, but it's patchwork of things built upon and stuck to the sides of the existing structure, optimizing towards a particular kind of "pragmatism" than towards any kind of elegance.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by ansgri on Sunday December 10, 2017 @08:02AM (#15891218)
I remember my colleague working with JSON in MATLAB via some thirdparty library about 2 or 3 years ago. It was regex-based, it was slow as hell but at least it was available.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by Derbasti on Sunday December 10, 2017 @03:22PM (#15893293)
Fun fact, I wrote my own JSON reader/writer in pure MATLAB, and it is also regex-based, and in many cases, it is faster than MATLAB's own, Mex-based JSON reader/writer: https://github.com/bastibe/transplant

There are few things as slow as non-vectorized MATLAB code. MATLAB's regex engine is pretty decent, actually, and supports quite a few fancy tricks. For example, I use the regex engine to find the start/end of all numbers and strings ahead of time, and for replacing escape sequences (even unicode escapes!) with their literal characters. The former is particularly important because otherwise, you'd have to manually iterate over characters until you find the end of strings or numbers, which is unacceptably slow in MATLAB.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by wirrbel on Sunday December 10, 2017 @07:52AM (#15891191)
CBOR or MsgPack are binary JSON-like encodings.

ProtoBuf depend on the schema definitions and encoder/decoder generation. Without the schema, you cannot read the format (theoretically), if you want your data to be read easily, JSON or CBOR or MsgPack are your best options.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by RantyDave on Sunday December 10, 2017 @11:29PM (#15895163)
I've been using cbor with python and it's been just fantastic. In particular it: Can send a "None"; Can tell the difference between bytes and unicode; and is real fast.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by ithkuil on Sunday December 10, 2017 @08:36AM (#15891302)
Encoding/decoding of protobufs can be done dynamically if you know the schema.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by wirrbel on Sunday December 10, 2017 @05:24PM (#15893815)
knowing the schema also means knowing the right revision of the schema. If you store messages for a while, this already can be a problem.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by ithkuil on Monday December 11, 2017 @05:35AM (#15896206)
schemaless is never really schemaless: the code that accesses your data is implicitly assigning it a schema, so you'll have the same problem. FWIW, protobuf schemas are designed to be friendly for back and forward compatibility; unknown fields can be ignored and "required fields are generally considered harmful", interesting read: https://github.com/google/protobuf/issues/2497
Re:Son: A minimal subset of JSON for machine-to-machine comm... by falcolas on Sunday December 10, 2017 @09:44AM (#15891573)
> there's little reason to use XML except for legacy or markup purposes.

There's also the ability to easily and explicitly encode data that doesn't fit to JSON's limited types. A non-exhaustive example includes: sets, hash tables that don't use string keys, tuples, imaginary numbers, fractional numbers, and precision decimal numbers.

There's also the fact that XML explicitly supports streaming interpolation of documents, something which can speed up interactivity quite dramatically.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by zbentley on Sunday December 10, 2017 @11:31AM (#15892105)
JSON has drawbacks, but I think you skipped one of its biggest benefits: it encodes in reasonably readable plain text.

Readable plain-text protocols remove a constant overhead from all debugging/introspection tasks. If you use, say protobufs, you'll still have to convert back into strings to see what was in individual messages. This makes reading, for example, logfiles or wireshark captures with "grep" more difficult. Sure, there are tools that you can throw before "| grep" that convert to text, but that's one more piece of cognitive/debugging overhead you have to remember, and one more thing that new developers have to know to do if they're used to the standard unix/text-oriented way.

That benefit applies even if your messages (or logs of messages) are stored/viewed in a database that speaks your binary protocol and provides tools to search/see the data as text. Whether or not you have something like that, it will always (always) be routinely necessary, or at least incredibly helpful to productivity, to "print out or search the textual content of messages sent/received by my code" when developing and testing apps that communicate over they network. A text protocol has a huge advantage in that department--or rather, it has a very small advantage that is present in a very large number of development/testing tasks.

Also, readable plain text is key. XML dialects, or e.g. Thrift's JSON format are plain text, but are not terribly readable. This is subjective, to be sure, but makes a big difference in practice.

There are great reasons to use binary protocols, but any comparison that leaves out the benefits of text content that is readable "for free" without using per-protocol tools is lacking.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by foobarian on Sunday December 10, 2017 @01:03PM (#15892571)
So this comes up constantly and I tend to agree with it, but it has always bugged me. We are programmers and we control the machines, so why can't we code our way out of this problem? Why isn't the very first thing one does when working on a protobuf system installing a custom version of utils and tools that deals with the wire format better? E.g. grep, less and wireshark that autoconvert protobuf messages?

(I know there are good reasons for this involving the effort required and maintenance etc. it just bugs me.)

Re:Son: A minimal subset of JSON for machine-to-machine comm... by teddyh on Sunday December 10, 2017 @04:48PM (#15893667)
Because Unix. Unix was designed as using ASCII text as a lowest common format, and all its tooling follows that design, and nothing has displaced this. If, for example, a Lisp system or a Smalltalk system had won out, I am sure we would all now be lamenting the inadequacies of s-expressions or Smalltalk objects instead of complaining about ASCII.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by zbentley on Sunday December 10, 2017 @08:21PM (#15894547)
While the "everything assumes unstructured text; destructure and restructure at will" paradigm is still incredibly powerful, and set the bar super high for data interoperability and uniformity, I think it lowered expectations for [meta]data complexity that could be supported by simple, small programs.

In Windows, PowerShell is a very good example of a low-ish-level (composable commandline apps and snippets) programming environment that isn't shackled by that paradigm.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by skybrian on Sunday December 10, 2017 @04:54PM (#15893692)
To do this right you'd need a common registry with all the proto schemas you'll ever want to use. It's a solvable problem, but it's comparable to setting up a new build ecosystem and getting people to use it. (Consider TypeScript and .d.ts files.)
Re:Son: A minimal subset of JSON for machine-to-machine comm... by ThrowawayR2 on Sunday December 10, 2017 @11:54AM (#15892222)
> Readable plain-text protocols remove a constant overhead from all debugging/introspection tasks.

As others have pointed out, text-based serialization has significant overhead. To save a few hours of debugging, you're willing to spend gigabytes of bandwidth, an uncountable number of CPU cycles and memory, and all the associated electricity and hosting costs over the lifetime of your service? Penny wise and pound foolish, to say the least.

Text-based serialization formats are just plain stupid for any type of service that handles over 100 requests per second. A good developer is not hampered in the slightest by the fact that their serialization format isn't text.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by zbentley on Sunday December 10, 2017 @01:30PM (#15892706)
Would I switch to a more computationally expensive format to save a few hours debugging? Probably not.

Would I switch to a more computationally expensive format to save a few hours debugging each time someone makes substantial changes to my application's message format? Very possibly.

Would I switch to a more computationally expensive format to prevent bugs (the easier it is to view, or remember how to view, what your code is sending/receiving, the less likely it is that lazy people will skip bug-hunting/QA steps that would show it)? Almost certainly.

Should you use a binary format if you're sending tons of data per second? Well, it depends. It's like microservices: if you have the tooling to make dealing with that format from the dev/debug/tracing side a breeze, go for it; using binary provides substantial savings, as you point out. If you don't have the tooling/time to make it as easy as text to introspect, and I mean that in the most absolute way, there might still be persuasive reasons to switch, but know that if you do, you are also buying a lot of "debuggability debt".

Re:Son: A minimal subset of JSON for machine-to-machine comm... by pjmlp on Sunday December 10, 2017 @12:40PM (#15892457)
Yep, we just replaced XML with JSON, while keeping the same loss of performance.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by redshirt on Sunday December 10, 2017 @08:38AM (#15891308)
I’d skip protobufs too. They’re horrible for performance. Many data center apps blow more cycles there than on compute. For actual applications where performance is necessary, binary “strict” formats are he only way to go. Protobufs are nice for ease of use, but they’re horrible otherwise.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by swalsh on Sunday December 10, 2017 @08:44AM (#15891332)
Maybe there's a middle ground between the 2.... like ASN.1
Re:Son: A minimal subset of JSON for machine-to-machine comm... by ci5er on Sunday December 10, 2017 @01:06PM (#15892589)
You mean a self-describing compact schematized format that's been around for 3 decades?

Please promote this as hard as you can. Then, us old guys getting aged-out of industry will be able to get jobs again.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by teddyh on Sunday December 10, 2017 @05:04PM (#15893737)
You’d need to repackage it in some form to make it palatable for modern audiences. Let me take a quick stab.

Make “ASN.2” or something, update the fundamental data types to modern standards (think of what changed from NeXTSTEP to macOS X; they changed from TIFF to PNG, from PostScript to PDF, etc. but kept the overall architecture the same). Consolidate and simplify the many options (but do not eliminate options entirely). And call it… JASN or something, which sounds like both JSON and ASN, and make up some acronym where the “J” stand for “Joint” (like in JPEG, which stands for Joint Photographic Experts Group).

And, maybe most importantly, make freely licensed tooling available for both converting to and from ASN.1 and JSON, but also jgrep, jless, jcat, etc. (similar to zgrep, zless and zcat, etc.) Make these packages available for all common operating systems, readily installable using that plaform’s usual mechanism.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by ktamura on Sunday December 10, 2017 @11:49AM (#15892196)
>but it has serious drawbacks such as the time and CPU resources it takes for parsing and the lack of schema.

Ditto. And if you still prefer the schema-free approach of JSON but with faster encoding and decoding support across all common programming languages, take a look at MessagePack.

Unlike JSON, MessagePack is optimized for speed and encodes common data types efficiently. Unlike Protobuf/gRPC, it requires no centralized schema.

MessagePack: https://msgpack.org/

Re:Son: A minimal subset of JSON for machine-to-machine comm... by Anderkent on Sunday December 10, 2017 @07:06AM (#15891074)
CBOR is pretty good if you just want to move data around.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by pagnol on Sunday December 10, 2017 @07:38AM (#15891146)
I didn't know CBOR, but it looks similar to BSON and MessagePack, or is there a significant difference?
Re:Son: A minimal subset of JSON for machine-to-machine comm... by heavenlyhash on Sunday December 10, 2017 @07:51AM (#15891186)
Roughly that it isn't shit.

I say that a bit tongue in cheek, but really: BSON has a monstrous amount of basic data types, some of which make very little sense and are very difficult to round-trip through other formats; and MessagePack had crippling basic sanity issues with what-are-bytes-vs-strings in its early history and that's something you simply can't recover from without declaring game over and making a new spec.

CBOR has neither of these issues. It's almost completely isomorphic to json, plus supports byte arrays. It's very nice.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by zbentley on Sunday December 10, 2017 @11:40AM (#15892144)
Does CBOR support lazy/partial deserialization? It's not a make-or-break feature, but the ability to pluck out individual fields from large MessagePack documents without deserializing the whole thing has been a significant performance/memory savings for me many times.

I haven't played with flatbuffers, but it probably supports this as well, given its design. Are there other binary protocols that have first-class (i.e. present with a good API in the client libraries for all major languages) support for lazy/partial deserialization?

Re:Son: A minimal subset of JSON for machine-to-machine comm... by js8 on Sunday December 10, 2017 @02:13PM (#15892949)
CBOR is very similar to MsgPack, so yes (if you design the schema well enough).
Re:Son: A minimal subset of JSON for machine-to-machine comm... by RantyDave on Sunday December 10, 2017 @11:31PM (#15895170)
More cbor ranting... In Python you can replace json.loads/dumps with cbor.loads/dumps with no further changes. Going back again may prove to be an issue when you discover just how much it is that json can't do.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by ci5er on Sunday December 10, 2017 @01:22PM (#15892673)
Is/Can CBOR be canonicalized (like ASN.1, for example) for the purpose of unambiguous generation and interpretation of hashes?

EDIT: I am happy to see that it handles date-time. Not really my favorite part of the non-spec of JSON on that front...

Re:Son: A minimal subset of JSON for machine-to-machine comm... by heavenlyhash on Saturday December 23, 2017 @02:25PM (#15995771)
You might be interested in IPLD in particular: https://ipld.io/

They use CBOR as the underlying serialization, and have a deep interest in canonicalization and applications of hashing.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by roller on Sunday December 10, 2017 @09:33AM (#15891523)
In the feature category, I'd also mention direct support for unbounded collections. CBOR can be its own container format for streaming data.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by user5994461 on Sunday December 10, 2017 @08:09AM (#15891233)
>>> ... and the lack of schema.

The json schema is standardized and available in most languages and platforms.

http://json-schema.org/

Re:Son: A minimal subset of JSON for machine-to-machine comm... by anilgulecha on Sunday December 10, 2017 @09:06AM (#15891405)
It's one schema pattern, but definitely not standardized. The homepage you link to also does not claim standardization.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by jack9 on Sunday December 10, 2017 @10:08AM (#15891705)
The json schema isn't a standard but is ubiquitous in California and in advertising (IAB standards). I dont know of anyone using another, or why you might.

It's like saying ruby isn't the only ruby language because it isn't a formal standard. So what?

Re:Son: A minimal subset of JSON for machine-to-machine comm... by lobster_johnson on Sunday December 10, 2017 @10:17AM (#15891739)
Ruby is perhaps not an ideal example, since it is in fact a formal standard (ISO/IEC 30170). Admittedly not updated beyond 1.8, but still.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by nly on Sunday December 10, 2017 @10:56AM (#15891932)
Ever tried writing a JSON schema? It's horrific.

I'd rather use Protobufs or Flatbuffers for specification and then rely on their built-in JSON serialisations.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by zbentley on Sunday December 10, 2017 @11:37AM (#15892135)
I don't think JSON schema is bad at all, for what it is.

Remember that the more modern binary protocols like protobuf/etc. don't serve the same niche as JSON schema at all: JSON schema validates external documents; i.e. you take a schema and make sure a document complies with it. Protobuf/flatbuffers/etc. validate internal documents, as they are encoded or decoded. If that's all you need, then the schema definitions for those products will be much friendlier than JSON-schema, but that's comparing non-equivalent things.

Another, minor quibble is that a lot of the schema-validation code in e.g. protobuf or Thrift is often generated by the framework, and the generated code can be quite hairy or confusing. There exist code generators for JSON schema as well, but writing a JSON schema by hand isn't comparable to, say, generating code from the Thrift IDL.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by nly on Sunday December 10, 2017 @12:13PM (#15892305)
Apache Avro follows a rather nice hybrid approach where the schema is required for decode (it's an untagged binary encoding) but the schema can loaded dynamically in to the library.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by user5994461 on Sunday December 10, 2017 @11:09AM (#15891991)
I wrote quite a few. I wouldn't call that horrific at all.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by perlgeek on Sunday December 10, 2017 @07:28AM (#15891124)
Please correct me if I'm wrong, but I've always had the impression that protobufs introduce more coupling than JSON.

Example: when you add a new element to the API response, the recipient needs to update their schema.

Is that correct? If yes, how do you deal with that in a microservice architecture where you have little control over consumers of your API?

Re:Son: A minimal subset of JSON for machine-to-machine comm... by icebraining on Sunday December 10, 2017 @07:48AM (#15891172)
"You can add new fields to your message formats without breaking backwards-compatibility; old binaries simply ignore the new field when parsing. So if you have a communications protocol that uses protocol buffers as its data format, you can extend your protocol without having to worry about breaking existing code."
Re:Son: A minimal subset of JSON for machine-to-machine comm... by maltalex on Sunday December 10, 2017 @07:55AM (#15891199)
> Example: when you add a new element to the API response, the recipient needs to update their schema.

That's not the case with protobufs. The sender can add new fields, and they will simply be invisible to receivers using the previous version of the message.

You'd need to update the receiver only if you want it to access the new fields, which is what you'd need to regardless of serialization format.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by schrodinger on Sunday December 10, 2017 @07:43AM (#15891157)
It’s true, but it’s also backwards compatible. That way you add the new field and consumers can update whenever they need to utilize the new field.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by weego on Sunday December 10, 2017 @07:39AM (#15891150)
I don't understand the issue. The contract between producer and consumer should never be fragile around additional values existing.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by zbentley on Sunday December 10, 2017 @11:49AM (#15892193)
> The contract between producer and consumer should never be fragile around additional values existing.

... it should never be fragile where fragility might cost more than it gains you. The open/closed principle is the right thing to follow in most cases, but not all.

For example, choking on unrecognized additional fields by default in development is often a big time/bug-saver, since it gives you an early "hint" that things might not be speaking the same dialect to each other.

Similarly, if you have a message convention that is heavy on "modifiers" which control irreversible things, sometimes it's better to be fragile rather than count on orchestration systems to work perfectly 100% of the time. Suppose you have a system for buying bicycles with a required field of "bike model", and modifiers of "color", "wheel size", etc. Now let's say your servers all got patched to expect a new modifier of "frame size" . . . except for one server which didn't restart due to a deployment bug, and is still serving traffic. If a client sends that unexpected additional modifier to the "old" server, and it gets ignored, this could result in sending a production order for an expensive unit with the wrong specifications. If not caught, that cost could be compounded by sending the wrong unit to the customer and pissing them off. Now, this is clearly not a problem with the message format, but rather with the orchestration/release system. But bugs in orchestration layers are incredibly common, and baking a bit of fragility into the messaging layer at the right places can help mitigate those bugs' impact.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by vkjv on Sunday December 10, 2017 @07:34AM (#15891140)
Yes, this is correct, but, it's also exactly what you want in microservices.

You are free to make forward compatible API changes without a deployment dance.

E.g., you can add a field in the service and the caller won't see it until it is prepared to handle it properly.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by ricardobeat on Sunday December 10, 2017 @07:24AM (#15891109)
Re:Son: A minimal subset of JSON for machine-to-machine comm... by pjmlp on Sunday December 10, 2017 @07:10AM (#15891084)
Υep, binary formats should be used when performance matters.

If the issue is debugging, writing a dump tool is a one time effort.

Re:Son: A minimal subset of JSON for machine-to-machine comm... by oneeyedpigeon on Sunday December 10, 2017 @07:25AM (#15891111)
When performance matters being the operative concept. Don’t optimise prematurely and throw out all the benefits of a textual format in favour of a binary one, unless you need to.
Re:Son: A minimal subset of JSON for machine-to-machine comm... by pegasuscollins on Sunday December 10, 2017 @08:48AM (#15891350)
When comparing the two, keep in mind that JSON is a self-descriptive format while protobuf is not.