Databricks Notebooks Best Practices

Databricks Notebooks Best Practices#

Batch Processing#

Notebooks are especially designed to process data in batches. We recommend using the following approach to handle large datasets:

  • Unless you have a specific requirement, we recommend using the default input and output fields. A smaller number of output fields can improve performance.

  • RecordID is Required for all input records and must be Unique. If you wish to use the same output table for multiple runs, make sure RecordID is unique across all runs.

  • To minimize the risk of duplicate requests caused by server outages or unknown issues during processing, we recommend the following approach:

    • Set log_to_table = True to monitor the process.

    • Pre-process the input source to make sure all RecordID are unique, make a clean copy of it. Split large datasets into smaller batches.

    • Process each batch separately. Avoid unnecessary loops in your script.

    • Combine the results if necessary.

    • Set duplicate_check = True to catch any duplicate RecordIDs.

      Note

      Enabling log_to_table = True amd duplicate_check = True may increase runtime, especially for large datasets. We recommend testing with and without this option to determine the best approach for your use case.

Log Table#

Important

We highly recommend enabling the Log table to facilitate troubleshooting in case of any issues.

To enable logging, set log_to_table = True and name the log table. This gives an audit trail as you run the the process. After failure, check the log table for execution details, event information, batching processing, and error messages.

Databricks License Key Set Up#

To securely store your Melissa license key in Databricks, open a notebook in the Databricks SQL Editor and follow these steps:

  1. Click the Terminal icon at the bottom-right of your screen.

  2. Copy the following command:

    databricks secrets create-scope melissa
    
  3. Right-click inside the Terminal to paste the command, then press Enter.

  4. Enter the following command:

    databricks secrets put-secret melissa license
    
  5. When prompted, paste your Melissa license key as the secret value.

  6. Press Enter to save your license key.

Once configured, the secret can be accessed across notebooks using the following Python code:

LICENSE_KEY = dbutils.secrets.get(scope="melissa", key="license")