EmailOperator for notifications in Apache Airflow - Time & Space Complexity
We want to understand how the time it takes to send emails using Airflow's EmailOperator changes as the number of emails grows.
How does the work increase when we send more notifications?
Analyze the time complexity of the following code snippet.
from airflow.operators.email import EmailOperator
def send_notifications(email_list):
for email in email_list:
email_task = EmailOperator(
task_id=f'send_email_{email}',
to=email,
subject='Notification',
html_content='Hello!'
)
email_task.execute(context={})
This code sends an email notification to each address in the list one by one.
- Primary operation: Sending an email using EmailOperator's execute method.
- How many times: Once for each email address in the input list.
As the number of emails increases, the total time grows roughly in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 email sends |
| 100 | 100 email sends |
| 1000 | 1000 email sends |
Pattern observation: Doubling the number of emails roughly doubles the work.
Time Complexity: O(n)
This means the time to send emails grows linearly with the number of emails.
[X] Wrong: "Sending multiple emails at once takes the same time as sending one email."
[OK] Correct: Each email requires its own send operation, so time adds up with each email.
Understanding how tasks scale with input size helps you design efficient workflows and predict performance in real projects.
"What if we batch multiple emails into one EmailOperator call? How would the time complexity change?"