Lecture 6-7
Lecture 6-7
Engineering
Prof. Roberto Pietrantuono
Lecture 6-7
Outline
• From Development to Deployment: Architectural Patterns
• Batch vs Stream Processing
• Microservices and Containers
• Deployment Example
• Microsoft Azure
• Pipelining
Where we are in the process…
Build
Plan
Release
+
Operate Model
Plan
Packaging/
Staging Predict
Build Serving
Build
Plan
Release
+
Operate Model
Plan
Packaging/
Staging Predict
Build Serving
Hyperopt,optuna
Github actions AutoML(AutoKeras)
Pip, Ant, Grade, Test Monitor (sklearn, Spark) Test Monitor
Maven, Docker, Github actions pipielines
Kubernetes,… Twine, pip, Mlflow (Model Version
BitBucket. Control: persisting) (sklearn, Spark)
pipielines
Github actions Drift detection
Analysis (e.g., Flake8 Mlflow (Alibi)
(linting), lack Comet.ml Evidently
(Formatting), ASA tools Seldon
(bug detection) Dev Pipeline is different than ML pipeline Neptune.ai
Testing (e.g., Pytest)
Useful Architectural (and ML) patterns
▪ …to increase quality while transitioning from development to
deploy
▪ The role of software architectures
▪ Separation of concerns
▪ Modularity
▪ Reuse
▪ Extensibility
▪ Technologies/tools
▪ From problem to solution: tuning cost-time-quality trade-offs
Design choices
• User-system interaction, interfaces design
• Persistence model, consistency model (recall: “Data conditioning” in
our functional architecture)
• Machine learning algorithm decisions (learning strategy, type of
algorithm, hyperparameters, training system, …; Recall: “ML” in our
functional architecture)
• Performance, efficient resource usage
• Distributed architectures (architectural patterns)
• Deployment options
• Software-to-hardware allocation (Recall: “Modern computing” in our
functional architecture)
• …
6
Architectural patterns
▪ Client/Server
▪ Two e Three-tiers
▪ SOA, MSA
▪ Shared data-Repository, Publish-Subscribe
▪ …
7
Principles
• SOLID principles:
• Single responsibility
• Open/Closed (“Open for extension but Closed for modification”)
• Liskow substitution: components with the same interface/contract can be
swapped
• Interface segregation (“no code should be forced to depend on methods it does not
use”, “don’t have multiple ways for components to talk to one another”, contract)
• Dependency Inversion (absrtact the interaction between high-level and low-
level modules)
1. High-level modules should not import anything from low-level modules. Both should
depend on abstractions (e.g., interfaces)
2. Abstractions should not depend on details. Details (concrete implementations) should
depend on abstractions
Useful Architectural (and ML) patterns
• IDEALS principles (for Microservices)
• Interface segregation
• Deployability: design and technology choices for packaging, deploying, running MS
• Event-driven: whenever possible, services activated by asynchronous message/event
• Availability over consistency: often, users value availability over strong consistency
• Loose-coupling
• Single responsibility: modeling microservices for one or few cohesive functionalities
Useful Architectural (and ML) patterns
Microservices Architecture (MSA)
• API Gateway
• A single entry point for clients.
• Benefits
• Request routing
• Load balancing
• Security and authentication
Microservices: key design patterns
• Service Discovery
• Locating service instances
dynamically.
• Types
• Client-side discovery
• Server-side discovery
• Tools
• Eureka
• Consul
• Zookeeper
Microservices: key design patterns
• How it Works:
>Failure threshold
• Opens the circuit when failures exceed Closed Open
a threshold
>Timeout
• Benefits: Failrue
• Resilience Half-open
Success
• Improved user experience
Microservices: key design patterns
• Saga Pattern
• Managing distributed transactions.
• Types:
• Choreography
• Orchestration
• Other patterns:
• Event Sourcing: Storing state changes as a sequence of events.
• CQRS (Command Query Responsibility Segregation): Separating read and
write operations.
• Strangler Fig Pattern: Gradually replacing parts of a monolith with
microservices.
• Asynch messages
Event-based design
• Pub/sub: Event data is published to
a message broker or event bus to
be consumed by other applications,
e.g. Apache Kafka.
• Event streaming: Process a
continuous flow of data in
something very close to real time, it
is not persisted at rest in a database
but processed as it is created or
received by the streaming solution,
e.g. Apache Storm.
Containers
Importance of Environment in ML Engineering
• Software deployment is a core aim of ML engineers
• Awareness of environmental requirements is crucial
• Different environments can impact code execution
• Challenges with Python Deployment
• Python lacks built-in support for standalone executables
• Requires a Python interpreter to run
• Needs relevant libraries and packages installed
• The Containerization Solution
• Containerization: Isolate applications and dependencies
• Create standalone units for diverse computing platforms
• Simplifies deployment and reduces compatibility issues
Containers
3
Containers
https://github.com/rpietrantuono/AISE_Ch5/