Exercise 2: On-Demand Query vs. Scheduled Function — Possible Solution ==================================================================== THE DIFFERENCE BETWEEN THE TWO ------------------------------ The on-demand dashboard query only runs, and only produces a result, at the moment someone has the app open and the ExpiryDashboard component actually executes it. The scheduled Cloud Function (onSchedule) runs on its own fixed timetable - once a day at a set time - completely independent of whether anyone has the app open at that moment. THE PROBLEM ONLY THE SCHEDULED FUNCTION CAN SOLVE ------------------------------ Per this chapter, the on-demand query can never notify someone who isn't currently looking at the app - if nobody opens the Food Tracker for several days, nothing about an item quietly expiring in the meantime ever reaches them. The scheduled function solves exactly this gap: it can check for expiring items and trigger a notification (or write a record the app surfaces on next open) regardless of whether the app is open at all, making the alert genuinely proactive rather than something the user has to remember to go check. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that the on-demand query is entirely dependent on the app being open at the moment it runs, and correctly identifies that only the scheduled function can reach a user who isn't currently using the app, which is the specific gap it exists to close.