Hey everyone! �* Building a Flutter app that sends users 1-3 location-based challenges per week based on their preferences.
The flow:
- User selects how many challenges/week they want (1-3)
- App sends notification during their free time slots
- 10 minutes to accept (can refresh once for a different challenge)
- If accepted, until midnight to complete
- Proximity notification (500-1000m) to remind them to take a memory photo
- Photos saved to user's collection
Technical approaches I'm considering:
First
- Weekly batch job that generates challenges for all active users via AI
- AI considers user location, preferences, previous trips, local events/weather
- Store generated challenges in DB with scheduled send times
- Use Appwrite's scheduled functions to trigger notifications
Second
Schedule random 1-3 times in the free time windows each week. Real-time generation when random time arrives → AI generates 2 challenges → send notification with primary, store secondary for refresh
Third
**On signup: **immediately generate 2 challenges (primary + secondary for refresh) with scheduled function Once user accepts/rejects both challenges → immediately create and prepare another 2 challenges If time runs out: user has to click "prepare new challenge" button → generates new pair but just shows "Wait for the notification for the adventure" screen This avoids inactive users costing $$ for AI calls
My questions:
- What's the absolute simplest way to architect this? Is it possible and viable to be done with Appwrite? I don't care much about costs, so if it's simpler I could skip batch processing entirely and just generate challenges on-demand when needed. It's just MVP.
- Simplest way to handle timezones? Convert everything to UTC?
- Any gotchas I should be aware of?
Since I'm inexperienced and I am learning backend as I go, any architectural guidance or simpler alternatives would be super helpful! Thanks! 🙏
App with randomly scheduled notifications + AI challenges - best approach?
The real-time generation (right before sending the notification) sounds like the most viable, because the AI can take into account events nearby + weather.
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)
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.
Ofc when creating new user I'd have something like generateWeeklyScheduleUntilNextCron(userId) - with way better name 😂 But yeah, those simple edge cases I can handle myself. I just want to be sure I start with decent-ish high-level plan before building.
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).
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
I think I would just have one longer running cron that executes at midnight sunday, this cron generates the tasks for every user. As the platform grows this probably won't work, but for a small MVP, I think it's fine.
still, something would have to triger notifications at the proper time 🤔
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.
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
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.
sounds do-able if i decided not to go with the bereal style of notis
with the bereal style, i only need 4 crons to generate tasks and send noti's (for each timezone), so its way simpler.
I'm not familiar with bereal :P
You can create an appwrite function that has the event for new user, when a new user is created the function is triggered that creates the task schedule
oh there's something like triggers in sql - on user create / new row?
Recommended threads
- I have try to use the appwrite in to the...
Invalid Origin. Register your new client (oailedjdbkhlkakmnnapoonllbnfmfij) as a new Web (Chrome Extension) platform on your project console dashboard
- what happened with 'never paused' ????
I can already imagine how annoying this is going to be...
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...