Arquitetura
Serverless para
Machine
Learning
Felipe Pereira
Felipe Pereira
https://www.linkedin.com/in/pereira-felipe/
https://github.com/pereiralabs/
● Professor
● Desenvolvedor
● DBA
● Arquiteto de Dados
● Data Engineer
● Data Scientist
A Jornada
Arquitetura do Sistema
Serviço de Machine Learning
Interface Avaliação e
Controle de Fluxo
Execução Retorno
Serviço de Machine Learning
Interface
Avaliação e
Controle de Fluxo
Execução Retorno
-REST
-Pub/Sub
-Lambda
-Airflow
-Step Functions
-Lambda
-Spark/EMR
-Sagemaker
-REST
-Pub/Sub
Entrada de
Dados
● API Gateway
● SNS + SQS
API Gateway
API Gateway
Swagger
SNS + SQS
SNS
SQS
Pricing
API Gateway:
● Free tier:
○ 1M API Calls
○ 12 meses
● Preço normal:
○
SNS:
● Requests:
○ 1M requests (free tier)
○ $0.50 / 1M
● Deliveries:
○ SQS/Lambda: grátis e sem limites
○ HTTP: Free tier (100K) | $0.60 / 1M
Workflow ● Airflow
● Step Functions
Airflow
Airflow
Airflow
Step Functions
Step Functions
Pricing
Airflow:
● Databases:
○ SQLite (padrão)
○ MySQL (recomendado)
○ PostgreSQL (com psycop2)
● Server
○ HTTP
● Pricing:
○ Como é instalado on-premise, depende de
como as tasks serão executadas. Tasks
pesadas, rodando localmente, precisarão de
mais recursos. O Airflow em si é leve,
podendo ser executado em EC2s menores.
Step Functions:
● Free tier:
○ 4.000 state transitions / mês
○ Sem limitação de 12 meses
● Preço normal:
○ $0.025 / 1K state transitions
Processamento
e
Predição
● Lambda + SciKit
● EMR
● Sagemaker
Lambda
Slide concedido por Felipe Santos - https://www.linkedin.com/in/felipe-santos-77854123/
Multi-threaded Data Science
EMR
EMR
Sagemaker
Sagemaker
Sagemaker
Pricing
Architecture Environment EC2 Type
Hours per
day
Hours per week
$ / Hour
(3 instances)
Monthly cost
EMR with
Lambda
Development 3 x r5.2xlarge 8 40 16,89 $ 2.972,64
Train 3 x r5.2xlarge 0 0 16,89 0
Predict Lambda 1 7 0,176 $ 5,28
Total 9 47 $ 2.977,92
Architecture Environment EC2 Type
Hours per
day
Hours per week $ / Hour Monthly cost
AWS
Sagemaker
Development ml.t2.xlarge 8 40 2,42 $ 425,92
Train
ml.m4.10xlarg
e
2 10 9,80 $ 431,20
Predict ml.m4.xlarge 24 168 7,28 $ 5.241,60
Total 34 7 7,28 $ 6.098,72
Architecture Environment EC2 Type
Hours per
day
Hours per week
$ / Hour
(c/ EBS)
Monthly cost
Lambda with
Scikit-Learn
Development r5.4xlarge 8 40 6,008 $ 1.057,40
Train 3 x r5.2xlarge 0 0 5,63 0
Predict Lambda 1 7 0
Total 9 47 $ 1.057,40
Pricing
Retorno de
Resultados
● REST
● SNS/SQS
● Banco de dados
Retorno de Resultados
REST ou SNS/SQS
API Gateway:
● Payload de 10 MB (por request)
● https://docs.aws.amazon.com/apigateway/latest/d
eveloperguide/limits.html
SNS/SQS:
● Payload de 256 KB (por mensagem)
● https://docs.aws.amazon.com/sns/latest/dg/sns-la
rge-payload-raw-message-delivery.html
(REST ou SNS/SQS) + Banco de Dados
Positivo:
● Retorna apenas uma flag de status
● Resultado no DB
● “Payload infinito”
Negativo:
● Acoplamento maior dos serviços
Model Health
Model Health
● Model Health (Acurácia, Precision, Recall, F1-Score, etc)
● Como calcular?
Model Health
● Model Health (Acurácia, Precision, Recall, F1-Score, etc)
● Como calcular?
Model Health
● Model Health (Acurácia, Precision, Recall, F1-Score, etc)
● Como calcular?
Visão de Produto
Produto
● Modelo de Machine Learning
● Data Pipeline (Ingestão, Transformação, Predição, Retorno)
● Case Management
● Feedback para o modelo (False Positive e False Negative)
● Integração com sistemas/serviços
Pessoas e Papéis
Pessoas e Papéis
● Product Owner - Backlog
● Data Engineer - Data Pipeline
● Data Scientist - ML Model
● Quality Assurance Analyst - Test
● DevOps - Deploy
Considerações Finais
● Planejamento de custos DENTRO da nuvem
○ Diferentes possibilidades
○ Diferentes preços
○ Diferentes arquiteturas
● Planejamento de custos ENTRE nuvens
○ Como isto influencia o projeto
○ Como isto influencia a empresa
○ Como isto influencia o cliente
● AWS Well Architected
○ https://aws.amazon.com/architecture/well-architected/
○
Obrigado!
https://www.linkedin.com/in/pereira-felipe/
https://github.com/pereiralabs/

Arquitetura Serverless para Machine Learning