Prefect est une alternative moderne à Airflow avec une meilleure developer experience. En entretien, on évalue la capacité à choisir entre les orchestrateurs et à architecturer des pipelines robustes.
Quelle est la principale différence architecturale entre Prefect et Airflow ?
# Test unitaire d'un flow Prefect (impossible avec Airflow sans mocking lourd)
from prefect import flow, task
@task
def extract(url: str) -> list:
return requests.get(url).json()
@flow
def pipeline(url: str = "https://api.example.com"):
data = extract(url)
return data
# Test simple en local - aucune infrastructure nécessaire
if __name__ == "__main__":
result = pipeline("https://api.example.com/orders")
print(result)Comment convertissez-vous un script Python existant en flow Prefect ?
from prefect import flow, task
from prefect.tasks import task_input_hash
from datetime import timedelta
@task(
retries=3,
retry_delay_seconds=60,
cache_key_fn=task_input_hash,
cache_expiration=timedelta(hours=1),
tags=["extraction", "api"]
)
def extract_data(source_url: str) -> list:
response = requests.get(source_url, timeout=30)
response.raise_for_status()
return response.json()
@task(log_prints=True)
def transform(data: list) -> pd.DataFrame:
df = pd.DataFrame(data)
df = df[df['amount'] > 0]
print(f"{len(df)} lignes après filtrage")
return df
@task
def load(df: pd.DataFrame, table: str) -> int:
df.to_sql(table, engine, if_exists='append', index=False)
return len(df)
@flow(name='pipeline-ventes', log_prints=True)
def pipeline(source: str = 'https://api.example.com/orders'):
data = extract_data(source)
df = transform(data)
n = load(df, 'orders')
print(f'{n} lignes chargées')
return nQu'est-ce qu'un Deployment Prefect ? Comment planifier l'exécution ?
from prefect.deployments import Deployment
from prefect.server.schemas.schedules import CronSchedule
# Créer un déploiement avec CRON
deployment = Deployment.build_from_flow(
flow=pipeline,
name='pipeline-ventes-quotidien',
schedule=CronSchedule(cron='0 6 * * *', timezone='Europe/Paris'),
work_pool_name='mon-pool-gcp',
parameters={'source': 'https://api.example.com/orders'},
tags=['production', 'ventes']
)
deployment.apply()
# Types de work pools :
# Process → exécution locale (dev/test)
# Docker → conteneur Docker isolé
# Kubernetes → pod K8s avec autoscaling
# Cloud Run → GCP serverless (facturation à l'usage)
# ECS → AWS serverlessComment gérez-vous les erreurs dans Prefect ? En quoi est-ce plus puissant qu'Airflow ?
from prefect.tasks import exponential_backoff
@task(
retries=3,
retry_delay_seconds=exponential_backoff(backoff_factor=10), # 10s, 100s, 1000s
retry_jitter_factor=0.5 # évite les retry storms
)
def call_external_api(url: str) -> dict:
...
# State handlers : réagir aux changements d'état
from prefect import flow
from prefect.states import Failed
def notify_on_failure(flow, flow_run, state):
if isinstance(state, Failed):
send_slack_alert(f"Flow {flow_run.name} a échoué : {state.message}")
@flow(on_failure=[notify_on_failure])
def pipeline():
...Comment choisissez-vous votre orchestrateur selon le contexte ?
| Airflow | Prefect | Dagster | |
|---|---|---|---|
| Paradigme | DAG-centric (tâches) | Flow-centric (Python pur) | Asset-centric (données) |
| Courbe apprentissage | Élevée | Faible | Moyenne |
| Écosystème | Mature, 400+ providers | Croissant | Croissant |
| Developer experience | Moyen | Excellent | Excellent |
| Data assets | Non natif | Partiel | Natif |
| Test local | Difficile | Très facile | Facile |
| Idéal pour | Équipes existantes, beaucoup de providers | Nouveaux projets Python-first | Teams data-asset oriented |
Comment monitorez-vous vos flows Prefect en production ?
| Niveau | Maîtrise | Signal GO | NO-GO |
|---|---|---|---|
| Confirmé | Flows et tasks, déploiements, retry basique, scheduling CRON | A transformé un script Python en flow Prefect, sait déployer avec un CRON et un work pool | N'a jamais utilisé d'orchestrateur, confond Prefect et Airflow |
| Senior | Work pools, state handlers, automations, comparaison orchestrateurs | Justifie le choix d'orchestrateur selon le contexte, a configuré des automations et alertes SLA | Ne sait pas expliquer la différence architecturale entre Airflow et Prefect |
Premier entretien gratuit. Rapport GO/NO-GO sous 48h.