You are reading a success story of avoiding premature optimization. I had to design an API for a service that receives some geographical data and returns the same data with additional information for each point of interest.
I heard of GeoJSON. You have features, each feature has geometry (coordinates), and each feature can also have properties for adding additional data. What I was uncomfortable with was its size.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.1, 0.55]
},
"properties": {
"prop0": "value0"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.7, 0.59]
},
"properties": {
"prop0": "value1"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [103.0, 1.5]
},
"properties": {
"prop0": "value2"
}
},
]
}
The format is very nice to read. You can generally understand what’s going on without reading a specification. The service used GeoPandas internally to process the data. I was able to parse the request and then return the response with one-liners. So I implemented the API with GeoJSON as the communication format.
When I came to the job the following morning, my little brain was screaming “this is such a waste of bandwidth.” I could write the same thing as CSV like this:
Longitude, Latitude, prop0
102.1, 0.55, value0
102.7, 0.59, value1
103.0, 1.5, value2
I could. But should I?
GeoJSON is widely supported by existing tools. I can throw it at QGis, Leaflet, OpenLayers and instantly see the data on a map. It’s versatile enough to be the method of choice for transferring geographical data between all internal APIs. And besides, if bandwidth was a problem, I have other tools at my disposal. Gzipping the request and response data, for example.
Looking back at this, I feel it was the right decision to stick with GeoJSON. I had an itch because of the size, but due to clarity and support for the format, I have lots of tools when it comes to debugging this.
If you want to read more along those lines, check out DRY is a footgun, remember to YAGNI by Swizec Teller.