Deployment Architectures

Welcome to the AI Deployment section of the course. We’ll journey from the fundamentals through to monitoring, infrastructure, and CI/CD - and we’ll see plenty of examples along the way.

Model deployment is the process of taking a trained machine learning (ML) model and making it available for people and applications to use.

Deployment choices affect the performance, scalability, and reliability of our model. In this section, we’ll explore common deployment architectures and their trade-offs.

This Lesson Will Cover
  • 🏗️ Common deployment architectures (monolithic, microservices, serverless, edge)
  • ⚖️ Pros and cons of different deployment approaches
  • ⏳ Batch vs real-time inference considerations
  • 📊 Visualizing deployment architectures with examples

Monolithic vs. Microservices

Monolithic Architecture

In a monolithic architecture, the entire application—including the model, business logic, and user interface—is built as a single, unified unit.

Example: E-commerce App

An e-commerce application that uses a recommendation model integrated directly into the backend.

Pros:

  • Simpler development workflow and deployment process
  • Lower operational complexity and infrastructure costs
  • Faster inter-component communication
  • Easier to maintain data consistency and transactions
  • More straightforward testing of end-to-end flows

Cons:

  • Harder to scale individual components independently
  • Technology stack is tightly coupled
  • Larger codebase can slow down development and build times
  • Changes require redeploying the entire application
  • Team coordination becomes challenging as the system grows

Microservices Architecture

Microservices break an application into smaller, independent services that communicate over APIs. Each service is responsible for a specific task, like serving predictions from an ML model.

Example: Weather App

A weather app where predictions from the ML model are served via a separate microservice.

Pros:

  • Independent scaling of components based on demand
  • Technology stack flexibility for each service
  • Smaller, more manageable codebases
  • Faster development cycles with independent deployments
  • Better fault isolation and resilience
  • Easier to understand and maintain individual services

Cons:

  • Increased operational complexity and infrastructure costs
  • Distributed system challenges (network latency, data consistency)
  • More complex testing and debugging across services
  • Need for robust service discovery and API management
  • Requires strong DevOps practices and monitoring
  • Higher initial development overhead
Machine Learning Deployment Architectures Mind Map
Mind map of ML deployment architectures discussed in this lesson. Above: Monolithic and Microservices, and below: Serverless and Edge.

Serverless Architectures

In a serverless architecture, we don’t manage the infrastructure directly. Instead, we deploy code or models to a cloud service (like AWS Lambda or Google Cloud Functions), and the platform handles scaling and resource allocation.

Example: Predictions Function

Deploying a trained model as a serverless function that returns predictions when called via an API.

Pros:

  • Flexible cost model: pay-per-use pricing for low-traffic applications
  • Auto-scaling: can handle traffic spikes without manual intervention
  • Zero server management: infrastructure maintenance handled by provider
  • Built-in redundancy: automatic distribution across availability zones
  • Security compliance: automated security patches and updates
  • Cloud ecosystem: seamless integration with cloud-native services

Cons:

  • Cost unpredictability: can be expensive at high, sustained workloads
  • Limited runtime: function timeouts (typically 5-15 minutes)
  • Cold starts: initial request latency due to container initialization
  • Platform constraints: limited control over runtime environment and configurations
  • Vendor lock-in: architecture often tied to specific cloud provider services
  • Resource limits: fixed CPU/memory allocations per function
  • Complex debugging: limited visibility into infrastructure and execution environment
  • State management: challenges with handling persistent data and long-running tasks

Edge Deployment

Edge deployment involves running the model directly on edge devices like smartphones, IoT devices, or edge servers.

Example: Face Detection

A face-recognition model running directly on a smartphone for biometric authentication.

Pros:

  • Low latency and offline capability: predictions made directly on the device without network dependency
  • Enhanced privacy and security: sensitive data stays on the device
  • Cost efficiency: reduced bandwidth and infrastructure needs

Cons:

  • Hardware constraints: limited storage, memory, and compute power
  • Deployment challenges: complex model updates and version control across devices
  • Development complexity: need for optimization and cross-device compatibility

Batch vs. Real-Time Inference

Batch Versus Real Time Inference Mind Map
Mind map overview of batch VS real-time inference, as discussed below.

Batch Inference

Batch inference processes multiple predictions at once, typically on a schedule.

Example: Product Recommendations

Generating product recommendations for all users overnight and storing them in a database.

Pros:

  • Efficient resource utilization through parallel processing of large datasets
  • Lower operational costs due to scheduled processing times
  • Easier to monitor and debug due to contained processing windows
  • Better handling of complex, computation-heavy models

Cons:

  • Delayed results: not suitable for applications requiring instant predictions
  • Storage overhead from maintaining prediction results
  • Risk of stale predictions between batch runs
  • Limited flexibility in handling unexpected requests

Real-Time Inference

Real-time inference generates predictions on demand as requests arrive.

Example: Chatbot

Product Recommendation Engine providing real-time personalized suggestions based on user behavior.

Pros:

  • More relevant results: recommendations adapt to current browsing patterns
  • Better user experience with personalized shopping journey
  • Flexibility to handle dynamic user preferences and inventory
  • Immediate feedback for purchase decisions

Cons:

  • Higher operational costs due to always-on infrastructure
  • Requires robust low-latency and high-availability systems
  • More complex scaling and load balancing requirements
  • Resource constraints may limit recommendation complexity

Visualizing Deployment Architectures

Here are a few simple diagrams to visualize different deployment setups.

Example ML Deployment Topologies Flow Chart
Architecture topologies for four ML applications, where arrows denote the flow of data.

Conclusion

This lesson provided a high-level look at deployment.

Although the examples were focused on AI/ML, you probably noticed that most of the concepts were broad principles for deploying software in general.

Key Takeaways

🏗️ Different deployment architectures (monolithic, microservices, serverless, edge) offer distinct trade-offs in terms of scalability, complexity, and maintenance.

🔄 Monolithic deployments are simpler but less flexible, while microservices offer better scaling but increased complexity.

☁️ Serverless architectures reduce infrastructure management but have limitations around execution time and cold starts.

🌍 Edge deployment brings computation closer to users but faces hardware constraints.

⏳ The choice between batch and real-time inference depends on latency requirements and resource constraints.

🎯 No single architecture fits all use cases—the best choice depends on scalability, latency, cost, and maintenance requirements.

Next: API Development

Hands-on learning is my favorite approach to teaching. That’s why I’m excited for the next couple of lessons, where we’ll build APIs with Python to deploy our models. 🚀

Comments (0)

No comments yet.