by imaginenore · 11y ago · 0 comments
Next I'd grid the area (maybe 250m2?) into blocks. When a user does a search, figure out his or her block, and start looking for cars in the current block, expanding outwards. You read-lock the blocks as you examine them. You only write lock 2 blocks as a car moves from one block to another (the blocks themselves would have a list of cars, maybe an array, maybe an rtree, maybe another grid).
It all falls apart when a single server can't handle all the load for a region. But then you could sub-divide the region, connect the servers with a queue (this car is now your responsibility), and let clients (not necessarily devices, but the api servers consuming these data servers) join the data.
The only case where I see 1 server failing is # of requests. All their drivers in the world probably fit in a few GB of memory (if that). 99% of a car's movement requires no locking (they stay in the same block), so there's very little write locking...I dunno...give it a 24 core server (or more)...
Maybe the problem is node and python. I don't know python runtime well enough, but this kind of setup is a nightmare for node. Sharing data across processes just isn't what it was meant to do (it rather fork and have a copy, but then your memory doubles per fork, and you have to keep it in sync). That's true for a lot of dynamic languages.
But sharding comes at the cost of complexity.
I work on an uber-like service and we use crude sharding between countries.
The problem is:
* sometimes your sharding is too coarse - eg. two cities which have no cross traffic
* sometimes your sharding is too fine - eg. cross border traffic
But the real complexity is;
* managing configuration and logic differences between countries and cities
* hosting so many different sharded clusters, routing between them, and keeping them all updated.
And that's where all the work goes.