Skip to content
Back

Realtime batching

  • 0
  • Databases
  • Functions
  • Realtime
D5
26 Aug, 2025, 19:05

I'm building a real-time boat tracker.

The idea:

  • A table stores the location updates of each individual boat.
  • Another table stores an aggregated JSON document with the positions of all boats. This JSON is sent to all clients with the real-time API.

If there are, for example, 100 boats updating every second, I would end up with 100 updates per second to the aggregated JSON, which is too frequent and creates high load for both clients and server. I want to limit the frequency of updates to the aggregated document (e.g., update it at most once per second), while still keeping all individual boat positions up-to-date. What would be the best approach to implement this?

TL;DR
Developers are discussing how to implement realtime batching using a separate table to store data temporarily. They suggest using a cron job to check for X amount of data or elapsed time before aggregating. Concerns about conflicting writes on the aggregate document are raised, with ideas about adding a cooldown in the function. The platform being used has a minimum time restriction for scheduling functions. The challenge lies in scheduling for a 1-second loop aggregation.
Kenny
26 Aug, 2025, 19:35

I think putting items in a queue and processing them at the same interval would probably work here?

Kenny
26 Aug, 2025, 19:37

I think I would have a boat location queue table that maybe has something like boat id, lat/lng, and status. Then fetch all that information to aggregate it and bulk update the queue status for them? that way you aren't aggregating a lot per second but once per second for every boat that is active?

D5
26 Aug, 2025, 20:13

The problem is who to schedule for 1s loop aggregation

Kenny
26 Aug, 2025, 20:14

Can you schedule a function that runs on a 1 second cron?

D5
26 Aug, 2025, 20:16

No 😔

Kenny
26 Aug, 2025, 20:18

why not? too many runs?

D5
26 Aug, 2025, 20:45

No, the minimum time is 1m

D5
26 Aug, 2025, 20:46

Appwrite doesn't allow you to set something less than that due to chron syntax

D5
27 Aug, 2025, 11:54

Well, maybe I can add some kind of cooldown in the function 🤔

Steven
27 Aug, 2025, 15:26

So you need something that gets the data and holds it until there's X amount of data or Y time has elapsed.

Once the time has elapsed, update the aggregate document.

You could do this with a function, but I'm slightly worried about conflicting writes on the aggregate document

D5
27 Aug, 2025, 15:26

Yes, that's the issue, how to hold it for X time

Mr. Afonso
27 Aug, 2025, 17:00

couldn't you have a separate table storing everything with a date/time, and then then either have a cron job running every few seconds checking if there are X amount of data or check the "oldest" data and see if Y time elapsed and if either happens, you just use that data however you need it like write it into another table

Mr. Afonso
27 Aug, 2025, 17:00

essentially using this table as a temporary storage

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more