#App with randomly scheduled notifications + AI challenges - best approach?

72 messages ยท Page 1 of 1 (latest)

robust storm
#

Hey everyone! ๐Ÿ‘‹

Building a Flutter app that sends users 1-3 location-based AI-generated challenges per week based on their preferences.

The Flow:

  1. User selects challenge frequency (1-3 per week)
  2. App sends notification at random time during day
  3. 10 minutes to accept (can refresh once for different challenge)
  4. If accepted, 24h to complete
  5. Proximity notification (500-1000m) reminds them to take memory photo
  6. Photos saved to user's collection

Technical Approaches I'm Considering:

Approach 1: Batch Generation

  • Weekly batch job generates all challenges for active users via AI including times to send noti
  • AI considers: user location, preferences, previous trips, local events/weather
  • Store challenges in DB with scheduled send times
  • figure out how to send noti's with challenges at these times

Approach 2: Just-in-Time Generation

  • Weekly batch job only schedules random notification times (1-3 per user)
  • Real-time AI generation when notification time arrives:
    • Generate 2 challenges per user
    • Send notification with primary challenge
    • Store secondary challenge for potential refresh
  • Problem: Not sure how to trigger functions at these dynamically generated times in Appwrite

Edge case for both: New users mid-week would need temporary scheduling until next Monday batch run.

My Questions:

  • What's the simplest architecture for this MVP? Is purely Appwrite possible for this use case - or do I need to create my own nodejs server with such custom logic?
  • Simplest timezone handling approach? Any gotchas?
  • Any other gotchas I should be aware of?

Since I'm learning backend as I go, any architectural guidance or simpler alternatives would be super helpful! Thanks! ๐Ÿ™

robust storm
#

App with randomly scheduled notifications + AI challenges - best approach?

robust storm
#

The real-time generation (right before sending the notification) sounds like the most viable, because the AI can take into account events nearby + weather.

jagged pendant
#

I think most of this should be accomplishable via Appwrite, you can do the batch job with an Appwrite function (https://appwrite.io/docs/products/functions) run it on a cron for the start of the week or something.

Store user information (like timezone, frequency, location, etc ) in a users collection, and pull from there when generating the tasks. Then a task collection to store the tasks, and information about them. (https://appwrite.io/docs/products/databases)

You can use Appwrite messaging to send out notifications when the task is due, probably another Appwrite function that runs every x number of minutes/hours/days to trigger which tasks are ready be kicked off. (https://appwrite.io/docs/products/messaging)

Things like the 10 min to accept would probably be handled by your frontend by just checking when the task was created against the time the user is trying to accept. Similar with the 24 hour to complete.

You could save photos using Appwrite storage (https://appwrite.io/docs/products/storage)

robust storm
# jagged pendant I think most of this should be accomplishable via Appwrite, you can do the batch...

Hmm all of this makes sense.
So I'd just run something like generateWeeklySchedule(userId) for every user every sunday/monday for example using batch job.

That's understandable, but now that I got 1-3 random times for each user for the upcoming week, how do I make sure I generate the task/challenge in that time and immediately send noti after. Something like generateTaskAndSendNoti(userId). I could use another batch job which runs every 15-30 mins for example and again checks every user/task that is due, but sounds like that's not a good way to handle this to me?

To be honest, I'm really not that experienced with backends etc. - so if batches and backend databases, etc. are built for this, I got no problem doing it this way. Just wonder if it's really the best (yet simple) way.

robust storm
robust storm
#

if there's no simple solution to this problem, I might just do it the "BeReal" way and just batch create all tasks at once at random time of day and send noti at the same time to all users who should have task generated this day. And I'd do this once per day (per timezone? continent? idk).

robust storm
# robust storm ---- if there's no simple solution to this problem, I might just do it the "BeRe...

The more I consider this approach, the more convinced I am that this model is the right direction. I'm feeling confident about developing a decent-ish architecture on my own, so thank you for all your guidance - it's been incredibly helpful.
When I have the architecture sketched out, would you mind if I run it by you? I'd really value your perspective on potential pitfalls or edge cases I might have missed, given your experience

jagged pendant
robust storm
jagged pendant
#

I would generate these tasks, off the top of my head I couldn't give you exact code for getting a timestamp for the next week, but I think you could probably do something with math.random and get the epoch time from sunday - saturday and use that to clamp the random epoch time.

robust storm
#

I found out upstash qstash / workflow or Google cloud tasks is exactly for that - executing scheduled events per user, but i'd love to stay in appwrite's ecosystem

#

least dependencies possible

jagged pendant
#

For notifications I would create a cron that runs every minute and pulls from your collection where task is for that minute and send out emails or notifications then

#

or you could do it a bit ahead and pull for tasks that are the next minute or something, I did something similar in a discord bot I made.

robust storm
#

with the bereal style, i only need 4 crons to generate tasks and send noti's (for each timezone), so its way simpler.

jagged pendant
jagged pendant
robust storm
jagged pendant
robust storm
#

nice

jagged pendant
robust storm
jagged pendant
#

So to me, I think you can push out a quick MVP with these functions

Cron:
Generate Tasks
Send Notifications

Event: users.*.create
Generate User Tasks

robust storm
jagged pendant
jagged pendant
robust storm
jagged pendant
# robust storm sounds a little bit more complex. the only thing i dont like is that cron which ...

Heres what I've done in a similar vein

      const now = new Date();
      const startOfMinute = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate(),
        now.getHours(),
        now.getMinutes(),
        0,
        0
      );
      const endOfMinute = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate(),
        now.getHours(),
        now.getMinutes(),
        59,
        999
      );

      const pendingReminders = await database.listDocuments<Reminder>(
        DATABASE_ID,
        REMINDER_COLLECTION_ID,
        [
          Query.equal('status', 'pending'),
          Query.between(
            'reminderDateTime',
            startOfMinute.toISOString(),
            endOfMinute.toISOString()
          ),
          Query.limit(5000),
        ]
      );
#

It only gets items for a specific minute of the day, but this isn't really scalable to millions of users. Though, I don't think that should be your concern at this point in development.

robust storm
# robust storm yeah exactly my thoughts

and its simpler to run 4 crons (for each timezone) everyday which creates random time and in that random time, i'd generate tasks for all eligible users (weekly limit not reached + in free day slot + keep it random) and send notis.

robust storm
robust storm
#

hope the question makes sense ๐Ÿ˜„

jagged pendant
robust storm
#

oh thats nice

#

okay, then crons every minute dont sound that bad

jagged pendant
#

Here is a good blog that explains the pricing

#

you have 1 hit for each call that returns nothing, so you would have at least 1440 operations per day if no tasks were created

robust storm
#

i will be on pro plan anyway so shouldnt be a huge problem, still sounds kind of "funny" as a solution to me (but im very inexperienced)

jagged pendant
jagged pendant
robust storm
#

i'd love to stay in 1 ecosystem tho to keep it very simple for me to understand and make changes etc. + less dependencies + i heard to stay away from google / firebase

jagged pendant
#

I guess from a quick look I'm not seeing how any of these are vastly different than appwrites functions, and how you wouldn't still have to poll for active tasks.

robust storm
# jagged pendant I guess from a quick look I'm not seeing how any of these are vastly different t...

it has this: notBefore, or delay in client.schedules.create(); not just cron... also i think i could use cron which runs everyday at random time because it has optional scheduleId to target cron and overwrite it to any time (so i could do that everyday)

or i could run the function every day for each timezone and just
await context.sleep("wait-for-random-time, $randomTime") // free limit is 7 days
/\ i could do this for each user as well if i wanted it to be random time for each user.

#

idk about google tasks, probably impossible there

robust storm
#

or is by any chance long delay/wait possible in functions @jagged pendant? so the cron which runs everyday at midnight would be something like this

timeUntil = generateRandomTime();
wait( timeUntil );

users = await getEligibleUsers();
createTasks(users);
sendNoti(users);

?

robust storm
#

sorry for asking question i could find in docs

jagged pendant
#

No problem, you found your answer?

robust storm
#

but still not sure if i can programmatically change crons in appwrite

jagged pendant
#

So I guess you could run your generate function, and use that to update the crons schedule

robust storm
jagged pendant
#

Other than that, I think you could do the generate function sets the first cron for the send notification, then at the end of the send notification run you could set the second, then third run?

robust storm
jagged pendant
#

So you would have 4 different functions that send notifications?

robust storm
#

i mean it would be 1 same function. idk how crons work yet exactly, maybe i can create 4 crons for 1 function ๐Ÿ˜‚

jagged pendant
#

You can't have 4 different crons schedules for 1 function

robust storm
#

so yeah, 4 functions. 1 for each timezone. they would act the same.

#

createTasks -> sendNoti

#

but the cron time for them would change to random time everyday at midnight.

that'd be done by another cron/function which runs every midnight.

#

Thanks a lot again @jagged pendant, i hope i wasn't annoying ๐Ÿ˜„ i appreciate it. i will prepare the architecture in the next 1-3 days -> think of every possible edge case etc and once it's done, I'd just let you know for a quick 5 minute check if you're okay with it?

#

im trying to place for shipaton with this project, so if i manage to place well or win i will give you a shoutout haha