
How we built a back end system for Uber-like maps with animated cars - dcu
https://blog.maddevs.io/how-we-built-a-backend-system-for-uber-like-map-with-animated-cars-on-it-using-go-29d5dcd517a
======
Animats
Nice. You have to choose between fast and realistic. If you run one fix, 15
seconds, behind real time, and compute a route between the last two fixes, the
paths will look good. But, as the author points out, when you order a car,
nothing will move for the first 15 seconds. The author doesn't say how they
dealt with that.

This is an old problem in multiplayer games. The usual solution is that the
sending client predicts the position linearly from the last two fixes, and
when the actual position differs from the prediction by some constant amount,
it sends an update. The receiving end uses the same prediction algorithm, so
its positions match the sending end with a maximum error of the same constant
amount, (plus some additional error due to lag.) Updates are also sent
periodically in case one gets lost, but those are not frequent.

Incidentally, Uber's display of cars on a map on the home screen is totally
fake.

~~~
azinman2
From talking to an uber engineer, he said that it's not fake, it's just
delayed.

~~~
bigiain
In my experience, I'd suggest it's delayed something like a month or two...

(Not that I've got a dog in the fight any more, don't forget today's the day
to delete Uber!)

~~~
sunilkumarc
Why would they display a month old data on your home screen? Either it's
realtime/delayed by a small amount of time or it's fake.

------
marknadal
For those interested, you can build a system like this that tracks sub-second
GPS information, and easily scale to 100M+ writes for $10/day with 1KB payload
(compare to the 62bytes in the article).

Here is a demo we threw together of it working in real life:
[https://youtu.be/7ALHtbC9aOM](https://youtu.be/7ALHtbC9aOM)

Here is a prototype of saving 100M+ writes for $10/day:
[https://www.youtube.com/watch?v=x_WqBuEA7s8](https://www.youtube.com/watch?v=x_WqBuEA7s8)

Our sync system: [https://github.com/amark/gun](https://github.com/amark/gun)

And since we are on the topic, I highly recommend this engineering blog post
by Discord on how they scaled up append-only writes in a way similar to how
our system does: [https://blog.discordapp.com/how-discord-stores-billions-
of-m...](https://blog.discordapp.com/how-discord-stores-billions-of-
messages-7fa6ec7ee4c7?gi=de801bddfd20#.dzqq7q4o7) .

~~~
socmag
Yes definitely room for improvement. We're pushing at least 8 billion a day
through our server.

By the way GunDB looks really cool. Nice!

~~~
marknadal
8 billion a day! That is great! You should write an article and post it. (or
if you know the OP you should mention this in the current article). What setup
are you using? Thanks - I'd love to learn your tricks.

------
dheera
One thing that always annoys me about the Uber UI is that the oversized cars
appear to be moving horribly slowly when they are sometimes actually moving
pretty fast. Every time I am waiting for an Uber I find myself wanting to
scream at the driver to step on the gas and go at least more than 5 mph which
is what it looks like on the UI. The scaling makes it hard to tell the actual
speed of the cars and the reasons when they slow down when they actually do
slow down. I don't have a good solution to this though. Maybe:

\- a car-game-like 3D interface where you can see the view from the driver's
seat, moving at the actual sensed speed of the car, with fake (or Street View)
scenery whizzing by, so while you are waiting you can see that the driver is
actually moving at close to the speed limit.

\- render a bunch of other random cars on the road, emulating the actual real-
time density of traffic, so if the guy is chugging along slowly I as the user
will blame the traffic, not the app or driver

\- render rain and snow in the 3D view if that is what is slowing the driver,
so I will curse at the weather for creating an unsafe situation and not the
driver for going slow

\- render ambulances and police cars in the 3D view if a traffic accident is
reported, so i will understand that a human is hurt instead of cursing at the
Uber app

\- show the state of red lights in real time so that when a driver is stopped
i know it is for a red light and not lazing around or lost directions. there
are enough Uber cars driving around that based on aggregate GPS statistics
they should be able to determine the cycle times and phases of every traffic
light on major streets.

~~~
blueline
>I find myself wanting to scream at the driver to step on the gas and go at
least more than 5 mph which is what it looks like on the UI.

sorry but regardless of the UI, does this scenario even make any sense? why
would your driver be going extremely slow unless there was a good reason for
it? I agree that the UI can be a bit misleading with speed but i think this is
a bit much

------
nevi-me
This is an interesting challenge, I'm building something similar for public
transport, and the latency in updates tends to make things bad.

On browsers I'm using turf.js to calculate movements and then animate them. I
calculate where the bus/train is likely to be in the next 30 seconds, and then
send that data through to the user. Then I keep updating the vehicle marker
frequently until that 30 seconds time out, or until another update comes in.

I'm struggling to do the same on Android because I haven't found a good
turf.js equivalent there.

~~~
jumasheff
Perhaps React-Native with turf.js will solve this?

Update: Here are React-Native Map components for Android and iOS
[https://github.com/airbnb/react-native-maps](https://github.com/airbnb/react-
native-maps)

~~~
nevi-me
I'm writing the parts of turf that I use in Kotlin for the JVM. Still early
work, but I try put in 30 minutes if my tired hours into the project, before I
sleep. I'll hopefully have something decent soon enough to make more progress
with the vehicles thing.

------
abusaidm
Hello, a question about mapping on mobile, How can one run mobile offline map
using OSM with an open source library, their screenshots doesn't contain
copyright, so am assuming their own solution.

thank you

~~~
tuukkah
[https://openmaptiles.org/docs/mobile/mobile/](https://openmaptiles.org/docs/mobile/mobile/)

OpenStreetMap license requires you to display an attribution though.

------
m3kw9
What accuracy people care is the car that you have just ordered. The other
times when you see a map of cars you can get away 80% of the time using
averages

------
perfmode
How does one manage sessions for mobile clients when communicating over UDP?
Do you just save the client's IP address and address the client by that IP?
Are the IPs of mobile devices relatively stable?

------
iamleppert
You don't need to send the full precision lat/lng in every update. Instead,
send only the change in position from the last update (in meters), which you
can calculate on the client.

You could also further reduce data by indexing the city into a grid, of, say 1
meter squares, or potentially a hilbert curve would be fun to experiment with.

~~~
zongitsrinzler
Since they use UDP this would not be foolproof

~~~
iamleppert
Well of course you need a way to deal with that, you could have a tolerance or
tolerated error and then if that gets over a threshold you request the full
precision location. Still loads more efficient than sending the full precision
every time.

------
rv11
for geoindices why not use redis?

~~~
nevi-me
Or Tile38
[https://github.com/tidwall/tile38](https://github.com/tidwall/tile38), I want
to try it out, it looks awesome

------
xt00
"Also we found challenge near Kremlin where car appeared at airport." /s

------
kozikow
Why not PostGIS?

