News for hackers. Stuff that matters.
Re:Some items from my “reliability list” by mahkoh on Thursday July 25, 2019 @02:12AM (#20523003)
On JSON:

"if you only need 53 bits of your 64 bit numbers"

JSON numbers are arbitrary precision.

"blowing CPU on ridiculously inefficient marshaling and unmarshaling steps"

On the other hand I am not blowing dev and qa time on learning/developing tools to replace curl/jq/browser/text editor.

Re:Some items from my “reliability list” by patrec on Thursday July 25, 2019 @05:15AM (#20523856)
> JSON numbers are arbitrary precision. > On the other hand I am not blowing dev and qa time on learning/developing tools to replace curl/jq/browser/text editor.

What a pleasant surprise it will be for you when you find out that jq silently corrupts integers with more than 53 bits.

Re:Some items from my “reliability list” by mr_crankypants on Thursday July 25, 2019 @09:04AM (#20524994)
It's perhaps less a limitation of JSON and more a limitation of JavaScript itself[1].

But still, given that easy consumption from JavaScript is the ultimate primordial reason for choosing JSON over other formats, it seems like trying to transmit integers with more than 53 bits of precision over JSON is asking for trouble. Because it's only a matter of time until someone will want to do something like write a new service in Node, and the JavaScript parsers for other formats are at least somewhat more likely to guide people toward using BigInt for large integers.

[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:Some items from my “reliability list” by apaprocki on Thursday July 25, 2019 @11:37AM (#20526291)
In TC39, we specified BigInt to not participate in JSON by default, precisely because emitting it as a native JSON number would not be able to be read back by JSON.parse() and many other environments would also not be able to parse it without extra logic if they simply use IEEE754 double.

I explicitly asked for and achieved step 2. in the modified SerializeJSONProperty algorithm[1] so that users could decide and opt-in to serializing BigInts as strings if they so choose, with or without some sigil that could be interpreted by a reviver function. e.g.:

  > JSON.stringify(BigInt(1))
  TypeError: Do not know how to serialize a BigInt
  ...
  > BigInt.prototype.toJSON = function() { return this.toString(); }
  > JSON.stringify(BigInt(1))
  '"1"'
[1]: https://tc39.es/proposal-bigint/#sec-serializejsonproperty
Re:Some items from my “reliability list” by awinder on Thursday July 25, 2019 @10:06AM (#20525440)
Or they'd just wrap as a string and move on with life, much as people do when they send uuids which should consume 128-bit as wide strings. The cases I've encountered that actually fundamentally required 64-bit ints are completely overshadowed by the cases where some well-intentioned developer decides to pack 64-bit ints with information to turn it into a uuid as well, so I really hope the consternation over this is from people who work a lot with mathematical apis/systems and not devs doing more heinous things with 64bit ints.
Re:Some items from my “reliability list” by patrec on Thursday July 25, 2019 @12:12PM (#20526589)
> I really hope the consternation over this is from people who work a lot with mathematical apis/systems and not devs doing more heinous things with 64bit ints.

No, it's typically IDs. And my observation is that inexperienced devs start out serializing 64bit IDs as ints and get burned first before they move to text.

There are several reasons why you end up with IDs > 2^53 even if 2^53 is good for enumerating ~100k things per earthling:

Many cloud providers will give you IDs that are specified to be 64 bit uints, and you'd better not corrupt some fraction of them. Generating unique integers strictly serially does not scale, so you might end up with something like Twitter's snowflake. Or you might want to tag additional info (reserve a few of the low bits for the type of id, or reserve particular ranges for particular types of acccounts etc etc).

I can promise you I have run into the issue in real life more than once and it's not just javascript and jq that like to silently corrupt ids by truncating them to double precision. For example pandas is really great at it as well.

What makes it especially fun that often only a very small fraction of IDs will be affected (< ~1 in 2000 if uniformly distributed).

Re:Some items from my “reliability list” by jdmichal on Friday July 26, 2019 @07:33AM (#20533963)
And this is why I say, if you don't do math on it, it's not a number! IDs are always strings. That we often choose to represent them more compactly as binary numbers is an implementation detail that should not be leaking out of your API.
Re:Some items from my “reliability list” by Aeolun on Friday July 26, 2019 @05:43AM (#20533547)
You need some integer to make 53 bits though...
Re:Some items from my “reliability list” by kristiandupont on Thursday July 25, 2019 @03:39AM (#20523438)
I don't understand why you are being downvoted. This struck me not as something that starts to "emerge after you've dealt with enough failures in a given domain" as the author claims, but more like a pet peeve.

The fact that JS has 53 bit precision will be a JS problem whether you use protobuf or anything else. On the other hand, if you are not using JS, it will almost certainly parse numbers of the precision that your language offers.

Re:Some items from my “reliability list” by TeMPOraL on Thursday July 25, 2019 @04:42AM (#20523700)
The original article's complaint wasn't (just) about 53 bits, but about using inefficient formats requiring constant serialization and deserialization for backend-to-backend communication.
Re:Some items from my “reliability list” by kristiandupont on Thursday July 25, 2019 @09:28AM (#20525187)
Protobuf or Thrift would require serialization as well? I still wouldn't do that (or, in fact, I am currently not doing that) before I have an incentive, i.e. performance problems. Of course, my services are all Nodejs at the moment, so JSON feels more natural there than it does in other environments.
Re:Some items from my “reliability list” by mr_crankypants on Thursday July 25, 2019 @09:48AM (#20525304)
One potentially nice thing about formats like Cap'n Proto is that they don't eagerly parse the message. You can just lazily grab the values you care about, which can be a big performance win if you typically only care about a few fields out of a larger message.

That's impossible with text-based formats like XML and JSON, because everything is fractally variable-length.

Re:Some items from my “reliability list” by bibabaloo on Thursday July 25, 2019 @05:02AM (#20523803)
It seems like its more "problems you deal with when you work at scale" like the author has at Google & FB.

At smaller scales, I think the (machine) benefits of using something like protobuf don't nearly outweigh the human benefits of just using JSON.

Re:Some items from my “reliability list” by gen220 on Thursday July 25, 2019 @08:41AM (#20524843)
I’m not sure how unpopular this opinion is, but I’d actually argue that there are underrated human benefits to using “just protobuf”, which are not shared by using “just JSON”.

1. Single source of truth for certain types, enums.

2. (assuming you’re using gRPC too) A separate, minimalist, and language-agnostic definition of your service interface, which you can document with comments to your heart’s content, and which (unlike other documentation) can NOT be out of sync with the actual service. I don’t have to read C++ to understand your C++ service should work.

3. Protobufs encourage message type / enum reuse, by allowing you to import other definitions. This might seem trivial, but it’s super important in mediumish orgs that everyone is using the same definition of time, geography, etc. It all adds up to less surprises when you open up a new .proto file.

The kicker is not that you can’t somehow get these things with JSON-over-HTTP, too. It’s that protobufs-over-gRPC won’t work without them. The trade off is that you can’t inspect raw requests unless you have built some tooling around it.

Re:Some items from my “reliability list” by C4stor on Thursday July 25, 2019 @10:58AM (#20525919)
I think the missing assumption is that doing "just protobuf" is not always a possibility when you in the end have an open API front-facing the internet.

So now there is a point in your codebase where you are receiving data in a JSON form. At this point having protobuf elsewhere is not chosing between JSON and protobuf, it's chosing between "json+protobuf" and "json".

Re:Some items from my “reliability list” by bluGill on Thursday July 25, 2019 @12:46PM (#20526941)
Not really. If you are sane you carefully parse all data from the internet and sanitize it first thing. json+protobuf is in fact an advantage because by keeping your internal and external data formats different you eliminate one class of mistakes where external data makes into internal systems. (this isn't perfect, you can change format without doing sanity checking but it makes it harder to do accidentally, and easier to find in an audit)
Re:Some items from my “reliability list” by gen220 on Thursday July 25, 2019 @01:12PM (#20527298)
In addition to what my sibling comment says about "sanitizing" external data – which I wholeheartedly agree with – the "open API front-facing the internet" is in the process of changing, if you're talking about normal websites.

gRPC-web isn't quite feature complete relative to normal gRPC, but it is getting pretty close, and the gains of avoiding JSON (de-)serialization would be big. I think once the protobuf story has a complete chapter for the front-end, bigger engineering orgs will roll it out much like they're rolling out typescript today.

If you're talking about actual developer/public-facing APIs, those will probably remain in JSON land for a while.

Re:Some items from my “reliability list” by xsmasher on Friday July 26, 2019 @02:58PM (#20537402)
#1 and #3 can be solved by using TypeScript types to define the schema of your JSON.

IMO they're readable enough to serve #2 too.

Before someone mentions "JSON schema" - I've tried to use them, and they're difficult to write and impossible to read. Reading/writing TypeScript types are a dream in comparison.

Re:Some items from my “reliability list” by mr_crankypants on Thursday July 25, 2019 @09:16AM (#20525090)
I find that the human benefits of using something like protobuf outweigh the human benefits of using JSON. The machine benefits are just a cherry on top.

Protobuf - or, more specifically, proto files - gives you a central place where you can define and also document your formats. You can throw an ASCII-field UML sequence diagram in there, if you need to. And it's right there in the single file that everyone will use to communicate the protocol, and the protocol at least can't change in any structural way without editing that file, so it's got a much higher chance of being kept up-to-date, and of being read by the people who need to read it, than any of the available options for documenting JSON-based protocols.

All JSON gives you is human readability, and browsers can read it without a library. The 2nd, I don't care about with back-end services. The 1st I don't really care about at all, because command-line utilities and library functions for dumping protobuf datagrams to a text format are a dime a dozen.

Re:Some items from my “reliability list” by tjpnz on Thursday July 25, 2019 @07:16AM (#20524377)
You don't even have to get close to Google or FB before running into issues with JSON. At a previous job we were working on REST APIs that topped out at around 100qps. Performance wasn't what we wanted and we were initially pointing the finger at Python and the database. We started profiling the application and found that most time was spent in JSON serialisation - which is actually implemented in C. Unless you're serving the browser there's really no excuse for not using a binary format.
Re:Some items from my “reliability list” by eternalban on Thursday July 25, 2019 @07:49AM (#20524558)
The excuse is that there are not enough seasoned software developers, and what used to be a relatively meritocratic discipline is now a shit show.

Problems started somewhere in early '00s when "software architect" became a dirty word, and one hit wonders like Paul Graham pontificated that "young is smarter".

And here you are.

Re:Some items from my “reliability list” by asark on Thursday July 25, 2019 @11:24AM (#20526168)
I've never seen JSON used in a project of any size at all where we didn't end up trying to hack constraints and types on top of it with some ugly and gross thing or another—looking at you, JSON Schema.

The more parts of your stack you tighten up, the fewer errors you'll hit and the more flexibility you'll have to use less-strict tools when it really matters. That's true at all but maybe the smallest scale. Worrying about the costs of having to document what you intend in a way your machines can verify—I mean, shouldn't you be doing that anyway?—is baffling to me. You don't need anything like Google scale to see the benefits of it. It's basic communication AFAI am concerned.

Re:Some items from my “reliability list” by pdpi on Thursday July 25, 2019 @07:44AM (#20524525)
This is not a binary, though. E.g. Thrift has multiple transport/protocol settings, such that you can use JSON over HTTP for debug/testing purposes while still using a nice, compact binary representation over a raw TCP socket for production.
Re:Some items from my “reliability list” by jlouis on Thursday July 25, 2019 @06:14AM (#20524127)
They both exist for a reason. JSON is really nice for your quick proof-of-concept where you have relatively few developers working on a small system. Up to a point, this also scales well.

On the other hand, if you have many developers, and the problem space starts converging toward scale, then certainly the problem space is different. Encoding of data cannot follow the language with the weakest type zoo, and efficiency starts to matter.

The hard part is to know when to make the switch, or when to anticipate growth in advance, such that you pick the right tool for the job.

It isn't just a question of the machine. For complex messaging, the added value of a well-defined message typing, provided by protobuf, will help. It will also remove a lot of problems if you have multiple different languages in the stack, talking to each other.

Re:Some items from my “reliability list” by parliament32 on Thursday July 25, 2019 @01:24PM (#20527397)
>JSON is really nice for your quick proof-of-concept where you have relatively few developers working on a small system.

This is really, really bad thinking and will always cause you a timebomb that will 100% explode on you in the long run.

"just a quick POC" will always end up being the actual product, and once you start down this path you end up with "let's just use mongo, it's schema-less, it'll be faster for devs and we can use a proper db later"... "let's just use nodejs for the POC, all the devs already know JS so it'll be great"... a few years later you end up with some gargantuan monstrosity that nobody wants to maintain, your "quick" language/db-du-jour is dead and unmaintained, you're EOL on four different software fronts and you now get to explain to the bosses why you need to rewrite the last four years of dev work.

Re:Some items from my “reliability list” by wil421 on Thursday July 25, 2019 @08:07AM (#20524661)
Once you hit the wall with JSON what format do you use? At a past job we were stuck using SOAP/XML middleware. We hit walls but I’m not sure if a different format would work. We ended up rate limiting lower priority traffic to get past our issues.
Re:Some items from my “reliability list” by q3k on Thursday July 25, 2019 @08:54AM (#20524926)
Protobuf/gRPC.
Re:Some items from my “reliability list” by juliusmusseau on Thursday July 25, 2019 @11:35AM (#20526278)
CSV.

Just kidding, but I suspect it would be a lot faster.

Re:Some items from my “reliability list” by Strilanc on Thursday July 25, 2019 @09:34AM (#20525214)
Re:Some items from my “reliability list” by mgraczyk on Thursday July 25, 2019 @02:20AM (#20523053)
That is not true of JSON numbers either practically or technically.

  This specification allows implementations to set limits on the range and precision of numbers accepted.
https://tools.ietf.org/html/rfc7159#section-6
Re:Some items from my “reliability list” by SahAssar on Thursday July 25, 2019 @04:50AM (#20523740)
Yes it is. All that part of the spec says is that it allows implementations to set/have limits on ranges and precision, which is obvious because for example javascript only has 53 bit numbers.

Other implementations can have other limits, but that does not mean that JSON itself or all implementations have the specific limits of javascript.

Re:Some items from my “reliability list” by mgraczyk on Thursday July 25, 2019 @01:50PM (#20527651)
It is not the case that JSON numbers are "arbitrary precision". JSON numbers are in fact "implementation defined" precision. The technical and practical implication is exactly what was described in the article: Since precision is implementation defined (not uniform and with no lower-bound), JSON numbers make a poor vessel for inter-service communication.
Re:Some items from my “reliability list” by megous on Thursday July 25, 2019 @05:25AM (#20523893)
Not anymore. Try writing 10000000000000000000000000000000000000000000000000000000000000000000000000000000n + 1n into your browser console.
Re:Some items from my “reliability list” by howdydoo on Thursday July 25, 2019 @04:41PM (#20529466)
Firefox:

    >JSON.stringify(1n)
    TypeError: BigInt value can't be serialized in JSON
Chrome:

    >JSON.stringify(1n)
    Uncaught TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at <anonymous>:1:6
I don't think we're quite there yet.
Re:Some items from my “reliability list” by megous on Saturday July 27, 2019 @09:41AM (#20541976)
It was counterpoint to "that does not mean that JSON itself or all implementations have the specific limits of javascript."

Javascript can do arbitrary precision integers now. So the last part is not true. You can generate your JSON strings with string concatenation in JS if you like.

Just because JSON.stringify has some limit doesn't mean JS has.

Re:Some items from my “reliability list” by apaprocki on Sunday July 28, 2019 @10:10AM (#20547615)
See my comment elsewhere in the thread that shows how to properly use BigInts with JSON.stringify, if you choose to support them in your environment.
Re:Some items from my “reliability list” by majewsky on Thursday July 25, 2019 @05:45AM (#20523982)
Well yeah, those are bigints, but JSON does not support bigints, so the point still stands.
Re:Some items from my “reliability list” by nemetroid on Thursday July 25, 2019 @07:53AM (#20524599)
If by "JSON" you mean "JSON parsers in web browsers", then yes.
Re:Some items from my “reliability list” by raverbashing on Thursday July 25, 2019 @07:09AM (#20524352)
I'm assuming the percentage of problems where the difference between 64 bits and 53 bits precision matter are really, really small (and you should be paying attention then, because you're bound to lose precision in other parts and not only in JSON)

For everything else, it is really a non-issue.

Re:Some items from my “reliability list” by jcoffland on Thursday July 25, 2019 @02:22AM (#20523064)
Javascript cannot handle 64-bit unsigned integers and the largest exact integral value is 2^53-1, but yeah JSON itself has no such restrictions.
Re:Some items from my “reliability list” by rimliu on Thursday July 25, 2019 @05:44AM (#20523978)
Javascript got BigInt:

   > 9007199254740991n * 9007199254740991n
   > 81129638414606663681390495662081n
Re:Some items from my “reliability list” by jlouis on Thursday July 25, 2019 @06:20AM (#20524154)
You can also just dump them into strings :)
Re:Some items from my “reliability list” by TeMPOraL on Thursday July 25, 2019 @04:41AM (#20523696)
> On the other hand I am not blowing dev and qa time on learning/developing tools to replace curl/jq/browser/text editor.

Because learning how to use correct tool for the job is so difficult and so outside of dev/qa job descriptions, that it's much better to waste compute on your servers and deal with performance and scalability problems.

Re:Some items from my “reliability list” by rimliu on Thursday July 25, 2019 @05:41AM (#20523959)
So the old "computer time is cheap, human time is not" is not true anymore?
Re:Some items from my “reliability list” by nvarsj on Thursday July 25, 2019 @06:26AM (#20524181)
I think that line is mostly propaganda from defenders of poor performing language runtimes. It’s not a dichotomy - both are important. Eg AWS bills can easily eclipse engineer salaries if you use it inefficiently.
Re:Some items from my “reliability list” by taffer on Thursday July 25, 2019 @09:11AM (#20525051)
> propaganda from defenders of poor performing language runtimes

Your comment is unnecessarily inflammatory.

> AWS bills can easily eclipse engineer salaries if you use it inefficiently.

If this happens, it is more due to architectural and algorithms problems than to the runtime of the language. There are many large applications written in Python, Ruby and PHP that run just fine.

Re:Some items from my “reliability list” by nvarsj on Friday July 26, 2019 @01:57PM (#20536807)
Yes, sorry, it was a bit over the top. I've been burned a few too many times by people who use that argument to justify poor tech decisions.
Re:Some items from my “reliability list” by Piskvorrr on Thursday July 25, 2019 @06:22AM (#20524168)
It is. OTOH, "these tools have been sufficient ten years ago, so I'm sticking to them forever" leads to wasting human time (by ignoring newer, potentially more efficient, tools).
Re:Some items from my “reliability list” by joshuamorton on Thursday July 25, 2019 @05:58AM (#20524033)
Strongly typed, schema'd data interchange leads to less human time in the long run.
Re:Some items from my “reliability list” by EdwardDiego on Thursday July 25, 2019 @07:49AM (#20524563)
Yep, you just have to put the time into ensuring that convenient <Serialisation X> utilities exist that offer the (near) same functionality of curl/jq etc.

It's a pain, but it's a short term pain, and necessary.

Re:Some items from my “reliability list” by TeMPOraL on Thursday July 25, 2019 @07:37AM (#20524481)
It is, but it's also true that spending a little bit human time on using the right tool for the job (and getting devs do their jobs) now might be cheaper in the long run that letting shoddy work slowly bleed your finances. Compute isn't free.
Re:Some items from my “reliability list” by empath75 on Thursday July 25, 2019 @08:02AM (#20524639)
Depends on how many computers doesn’t it? It’s pretty easy for one developer to put code on many thousands of servers.
Re:Some items from my “reliability list” by LaGrange on Thursday July 25, 2019 @08:53AM (#20524917)
> On the other hand I am not blowing dev and qa time on learning/developing tools to replace curl/jq/browser/text editor.

Is your turnover so high that learning a single tool is a significant portion of employee costs?

Re:Some items from my “reliability list” by raxxorrax on Thursday July 25, 2019 @09:50AM (#20525320)
Why not just use SOAP?

I think recent experience should tell us that the easiest thing plainly wins out. JSON can be terrible, Javascript can be terrible, but limitations on large integers isn't the worst hurdle to take.