Skip to content

API: Reduce JSON data sizes to cut traffic costs and improve performance #37

Description

@RalphBike

Disclaimer 1: I know this is not the right place for this ticket, but the API repository is closed and read-only. As discussed with @mltbnz , I am opening this ticket here, please feel free to move it.
Disclaimer 2: I am not sure if all my assumptions or findings are correct. Please excuse if I got something wrong or do not have a full picture.

TL;DR: The current JSON format is inefficient and generates lots of traffic. Therefore I suggest several actions to reduce data size and costs. All actions are sorted from least intrusive to more complex.

I had a closer look at the data provided by the back end and would like to suggest some improvements to reduce traffic, cut hosting costs and improve performance and stability for all users.

Current status

  • The app gets the user positions from the server in JSON format. The current JSON is valid but not very efficient: it contains non-functional unnecessary white space and long identifiers like "device", "latitude", "longitude", "timestamp" which are used repeatedly.
  • The values for lat/long, ID, and timestamp are longer than needed.
  • There are very little or none optimizations on the server in place: server side compression (transfer encoding) is not supported.
  • I do not think there is any location filter in place which would provide each user only positions in his area. Instead every user downloads all the device positions on the planet all the time.
  • Users of the mobile clients (at least on Android) are never asked if they still want to send there position or if they would like to either become an observer or shut down the app. This creates useless traffic, spoils data quality and invades user privacy.

Suggested changes

(sorted by effort to implement, least expensive first)

1. Requiring no changes on the clients
1.1. Reduce all unnecessary white space/blanks from the JSON. Or minify it.
1.2. Enable server side compression (transfer encoding).
1.3. Reduce device ID length from 128 characters(android)/40 characters (Iphone) to 40/40 or 32/32. Even further reductions should be doable without collisions.

2. Little changes on the clients
2.1. Implement a region of interest (ROI) filter on the back end to make sure only devices are downloaded that are relevant to the user (visible in the current view port plus some border around). The clients should only requests data for their current viewport (plus some more) and the server should only provide the needed positions. In case of changes to the map (zoom/move/etc.), the clients needs to request new data. URL could be something like ...?latMin=53.528&latMax=53.579&lonMin=9.818&lonMax=10.181.
2.2. Implement a timeout for position sending and a position check on all clients to prevent people from sending their positions for many hours or sending their unchanged position for a long time. E.g.: ask the users after 4 hours of sending, if they really want do continue. And: ask the user if they still want to send after 30 minutes without a change of the position.

3. Larger changes to the clients
3.1. Use a more efficient JSON format, without the repeated use of long identifiers, see below.
3.2. Reduce GPS precision from 6 decimals (Precision 11.11 cm) to 5 digits (Precision 1.11 meters).
3.3. Use delta timestamps within the JSON and only one absolute timestamp per JSON.

Sample JSON code for one device

Old JSON, 245 characters per device:

{"device": "3a65e13300839ab0727a355179b4eb7319490e363a65e13300839ab0727a355179b4eb7319490e363a65e13300839ab0727a355179b4eb7319490e363a65e13300839ab0727a355179b4eb7319490e36", "latitude": 53183718, "longitude": 12974962, "timestamp": 1779483918},

New JSON, 56 characters per device:

["4a4ae4a6a0c559a40cb94e04226b398e",5249335,1337942,27],

Combined with the compression I would expect to bring traffic down by factor 5-10, with the ROI filter even more.

I have working proof-of-concept code for all of the changes and am happy to assist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions