A better fix could have been switching to some other (binary) serialization protocol (BSON or similar) - the problem here doesn't seem to have been the size of the history itself, but the exponential growth of the escaping.
jo.put("previous", previous);
Rather than jo.put("previous", previous.toJson());
Presumably the reason they didn't do this is because they couldn't handle a recursive schema?And then the whole thing was "encrypted"... with a static RSA key. I don't mean they used a stream cipher based on a hard-coded key, which would bad enough. No, they used the RSA keys directly for bulk data encryption.
I flat rejected their solution, then was overruled as being "too picky", and this monstrosity went into production.
data Screen = Screen {
previous :: Maybe Screen,
...
}
is inferior to what they eventually had, data ScreenHistory = ScreenHistory {
previous10 :: [Screen],
current :: Screen
}
-- Screen itself is nonrecursive
But I do think that storing JSON as a string was a weird antipattern in the first case, smacking of a premature optimization.Recursively serialized JSON, XML, whatever is a code smell in general.
(Note that outside certain examples like this, in general BSON is not smaller than JSON. You'd need something like protobufs. )