You have a Firebase scheduled function set to run every 5 minutes using the cron expression */5 * * * *. What will be the behavior of this function?
exports.scheduledFunction = functions.pubsub.schedule('*/5 * * * *').onRun((context) => { console.log('Function executed'); return null; });
Think about how cron expressions align with clock time.
The cron expression */5 * * * * means the function triggers at every 5th minute of the hour, aligned with the clock (e.g., 00:00, 00:05, 00:10, etc.).
Which of the following Firebase scheduled function definitions will deploy without syntax errors?
Check the valid cron syntax for Firebase scheduled functions.
Firebase scheduled functions accept cron expressions or specific strings like 'every 10 minutes'. However, 'every 10 minutes' must be exact. The expression '*/10 * * * *' is a valid cron expression for every 10 minutes. 'every 10 mins' is invalid.
You want to create a Firebase scheduled function that runs daily at midnight UTC to clean up old data. Which design choice ensures the function runs reliably even if the function code is updated frequently?
Consider how Firebase scheduled functions handle redeployments and schedules.
Firebase scheduled functions keep their schedule as part of the deployment. Redeploying updates the schedule. Using the cron expression '0 0 * * *' ensures the function runs daily at midnight UTC. Frequent redeployments update the function code and schedule together, which is normal practice.
Which statement best describes the security model of Firebase scheduled functions?
Think about who triggers scheduled functions and their privileges.
Firebase scheduled functions run in a trusted environment with administrative privileges. They are triggered by the Firebase infrastructure, not by users, so they do not require user authentication.
You have a Firebase scheduled function running every minute to process queued tasks. The function sometimes runs longer than a minute, causing overlapping executions and increased costs. What is the best approach to optimize cost and avoid overlaps?
Consider how to prevent multiple function instances from processing the same tasks simultaneously.
Implementing a locking mechanism (e.g., using Firestore or Realtime Database flags) allows the function to detect if a previous run is still active and skip execution, preventing overlaps and reducing costs while keeping the schedule frequent.
