Firebase Functions Scenario-Based Quiz for Interview Success Quiz

Assess your understanding of serverless function concepts and real-world scenarios within Firebase Functions. This quiz is designed to help developers prepare for interviews by focusing on core principles, event-driven triggers, error handling, deployment, and security practices in a serverless environment.

  1. Choosing the Right Trigger for Upload Events

    Which type of trigger should you use to automatically process an image when it is uploaded to cloud storage?

    1. HTTP trigger
    2. Realtime Database trigger
    3. Storage trigger
    4. Auth trigger

    Explanation: A Storage trigger listens for events related to file uploads or changes in cloud storage, making it ideal for automatically processing images. HTTP triggers are designed to respond to direct HTTP requests, not storage events. Auth triggers handle authentication changes, and Realtime Database triggers respond to changes in database data, not file uploads.

  2. Understanding Function Timeout

    If a function runs significantly longer than expected and does not finish within its maximum timeout, what will most likely happen?

    1. The function keeps running indefinitely
    2. The function is forcibly terminated
    3. The function automatically retries forever
    4. The function result is cached

    Explanation: When a function exceeds its maximum allowed timeout duration, it is forcibly terminated to prevent excessive resource use. Functions do not run indefinitely under such circumstances. Automatic retries occur only for specific event types and are not endless. Caching of results does not occur when timeouts are reached.

  3. Securing Sensitive Environment Variables

    In a scenario where your function uses an API key, what is the preferred way to keep this key secure and out of your source code?

    1. Include the key as a URL parameter
    2. Store the key as an environment variable
    3. Hardcode the key inside the function
    4. Save the key in a public database

    Explanation: Storing sensitive information like API keys in environment variables keeps them out of the codebase and enhances security. Hardcoding such data risks exposure if the code is shared or versioned. Storing keys in a public database or exposing them as URL parameters also makes them vulnerable to misuse. Environment variables are the safest listed method.

  4. Handling Function Deployment Versioning

    After deploying a new version of a function, what happens to requests sent to the previous version?

    1. Users can choose which version to use
    2. Requests are evenly balanced between all versions
    3. Older versions remain active for 24 hours
    4. Requests are routed only to the latest deployed version

    Explanation: Deploying a new function version routes all subsequent requests to the latest code, ensuring consistency. There is no built-in mechanism to balance requests across different versions, nor can users select their preferred version. Older versions are typically replaced immediately rather than remaining active for a set duration.

  5. Event-Driven Function Retries

    When a background function triggered by a database change fails due to a temporary error, what is the default behavior regarding retries?

    1. The function is retried automatically
    2. The function requires manual restart
    3. The function is ignored and deleted
    4. The function sends alerts and stops retrying

    Explanation: By default, background functions responding to database events are retried if they fail, unless configured otherwise. The function is not simply ignored or deleted upon failure. Manual restarts are unnecessary for such automated retry mechanisms. Alerts may be sent if set up, but do not influence retry behavior by default.

  6. Validating User Input in Functions

    If your function processes user-provided data such as usernames, what is a recommended best practice before acting on it?

    1. Accept data without checking
    2. Validate and sanitize the input data
    3. Store unverified data directly
    4. Display input data to all users

    Explanation: Validating and sanitizing user input prevents abuse, data corruption, and possible security vulnerabilities. Simply accepting or storing data without checks increases risk. Displaying unverified data can expose users to inappropriate or malicious content. Input validation and sanitization are crucial safeguards in processing user data.

  7. Choosing the Function Location for Compliance

    If your serverless function must comply with local data residency requirements for the EU, what should you do during deployment?

    1. Ignore region selection
    2. Deploy to all regions simultaneously
    3. Use the default global region
    4. Select a deployment region located in the EU

    Explanation: Selecting a regional deployment within the EU ensures compliance with local data residency laws. The default global region does not guarantee where data is stored or processed. Deploying to all regions is often unnecessary and can increase complexity. Ignoring the region could result in violating compliance requirements.

  8. Understanding the Purpose of HTTP Functions

    Which scenario best fits using an HTTP-triggered function instead of a background event-based function?

    1. Listening for database changes
    2. Exposing a REST API endpoint for client requests
    3. Monitoring authentication events
    4. Responding to file uploads in storage

    Explanation: HTTP-triggered functions are suited to handle direct client requests, such as providing API endpoints. Responding to storage uploads, authentication, or database changes are better handled by event-driven triggers specialized for those services. HTTP triggers are not intended for background event processing.

  9. Mitigating Infinite Loops in Triggered Functions

    Suppose a function modifies a database document and is also triggered by changes to that document. What problem might this cause if not managed?

    1. It improves speed automatically
    2. It may cause an infinite trigger loop
    3. It will block all other triggers
    4. It optimizes database usage

    Explanation: When a function both triggers on, and modifies, the same document, it risks entering an infinite loop as each change refires the trigger. This does not block unrelated triggers, nor does it automatically optimize performance. Infinite loops can cause high resource usage and unintended behavior.

  10. Detecting Function Invocation Source

    How can you typically determine if an HTTP-triggered function was called by an authenticated user?

    1. Rely only on request headers' presence
    2. Use the request's IP address
    3. Assume all requests are authenticated
    4. Check the request for a valid authentication token

    Explanation: The presence of a valid authentication token in the request allows the function to verify user identity. Not all requests are authenticated by default, so assumptions can lead to insecurity. While headers may carry authentication data, not all headers indicate authentication. The IP address provides no confirmation of authentication.