Pertemuan 6: Serverless Computing Progress: 0%

Implementasi Solusi Serverless

Event-Driven Computing tanpa Server Management

No Server Management: Fokus pada kode aplikasi tanpa mengelola infrastruktur. Automatic scaling, pay-per-use pricing, dan event-driven execution.

Tujuan Pembelajaran

Memahami Arsitektur Serverless

Event-driven computing, function-as-a-service, dan manfaat serverless

Implementasi Function di Berbagai Platform

AWS Lambda, OpenNebula Functions, Huawei FunctionGraph dengan best practices

Optimasi Performa dan Biaya

Cold start mitigation, memory optimization, dan cost-effective design patterns

Arsitektur Serverless Computing

Event Sources

API Gateway, S3, Database

Function

Serverless Function

Services

Database, Storage, APIs

Cost Efficiency

Pay-per-execution model eliminates idle resource costs

$0 When Idle
Sub-second Billing
Auto-scale No Over-provision

Automatic Scaling

From zero to thousands of concurrent executions instantly

0 → 1000 Instantly
100% Availability
No Config Required

Reduced Complexity

Focus on business logic without infrastructure management

NoOps Approach
Fast Deployment
Micro Services

Traditional vs Serverless Architecture

Traditional (Monolithic)
// Server-based Application const express = require('express'); const app = express(); // All routes in one application app.get('/users', (req, res) => { // User management logic }); app.post('/orders', (req, res) => { // Order processing logic }); app.put('/products', (req, res) => { // Product catalog logic }); // Server always running app.listen(3000, () => { console.log('Server running on port 3000'); });
Serverless (Microservices)
// User Management Function exports.usersHandler = async (event) => { // Only user-related logic return { users: [...] }; }; // Order Processing Function exports.ordersHandler = async (event) => { // Only order-related logic return { orderId: '123' }; }; // Product Catalog Function exports.productsHandler = async (event) => { // Only product-related logic return { products: [...] }; }; // Each function runs independently // No server management required

Platform Serverless Comparison

OpenNebula Functions

Deployment: Private Cloud, On-premises

Isolation: VM-based, Container-based

Customization: Full control over runtime environment

Pricing: Resource-based (no per-request charges)

# OpenNebula Function Template FUNCTION_TEMPLATE = { name: "image-processor", type: "serverless", memory: 512, runtime: "python3.9", timeout: 300, triggers: ["s3-object-created"] }

Huawei FunctionGraph

Runtime Support: Custom images, Multiple languages

Max Memory: 32 GB

Timeout: 30 minutes (extendable)

Pricing: $0.00000018 per request + $0.000015 per GB-second

// Huawei FunctionGraph Handler def handler(event, context): logger = context.getLogger() logger.info('Event: %s', event) return { 'statusCode': 200, 'body': 'Hello from FunctionGraph!' }

Azure Functions

Runtime Support: .NET, Node.js, Python, Java, PowerShell

Durable Functions: Stateful workflows

Premium Plan: VNet integration, unlimited execution duration

Pricing: $0.0000002 per request + $0.000016 per GB-second

// Azure Functions Handler [FunctionName("HttpTrigger")] public static async Task Run( [HttpTrigger(AuthorizationLevel.Function)] HttpRequest req) { return new OkObjectResult("Hello from Azure Functions!"); }

Implementasi Praktis Serverless

AWS Lambda Configuration

# serverless.yml - AWS Lambda service: my-serverless-app provider: name: aws runtime: nodejs18.x region: us-east-1 memorySize: 512 timeout: 30 functions: hello: handler: handler.hello events: - http: path: hello method: get cors: true - s3: bucket: my-trigger-bucket event: s3:ObjectCreated:* processImage: handler: handler.processImage memorySize: 2048 timeout: 300

Serverless Pricing Calculator

Enter values above to calculate cost

Cold Start Simulation

Cold start terjadi ketika function dijalankan setelah periode idle. Simulasikan prosesnya:

Request
Container Init
Runtime Start
Function Load
Execution
Ready for simulation

OpenNebula Serverless Implementation

OpenNebula Functions Architecture

OpenNebula menyediakan kemampuan serverless melalui VM-based functions dengan kontrol penuh atas lingkungan runtime.

Function Template
# OpenNebula Function Template NAME = "python-data-processor" MEMORY = 2048 CPU = 1.0 CONTEXT = [ FUNCTION_NAME = "process_data", RUNTIME = "python3.9", HANDLER = "lambda_function.lambda_handler", REQUIREMENTS = "requirements.txt", TIMEOUT = "600", ENVIRONMENT = "production" ] DISK = [ IMAGE_ID = "15", TARGET = "vda" ] # Network configuration NIC = [ NETWORK_ID = "3", SECURITY_GROUPS = "0" ]
Trigger Configuration
# Trigger-based Execution TRIGGERS = [ { "name": "s3-upload-trigger", "type": "s3_object_created", "bucket": "input-bucket", "prefix": "uploads/", "suffix": ".jpg" }, { "name": "api-gateway-trigger", "type": "http", "method": "POST", "path": "/process", "auth": "iam" }, { "name": "schedule-trigger", "type": "cron", "schedule": "0 2 * * *", "enabled": true } ]
OneFlow Serverless Workflow
Enterprise Ready
# OpenNebula OneFlow Serverless Service SERVICE_TEMPLATE = { name: "serverless-data-pipeline", deployment: "straight", roles: [ { name: "data-ingest", type: "vm", cardinality: 2, min_vms: 1, max_vms: 10, elasticity_policies: [ { type: "REACTIVE", expression: "MAX(CPU_USAGE) > 80", adjust: 2, min: 1, max: 10 } ], scheduled_policies: [ { type: "PERIODIC", adjust: -1, min: 1, max: 3, start_time: "02:00", recurrence: "0 2 * * *" } ] } ], networks: { "serverless-network": { type: "vnet", extra: "BRIDGE=br0" } } }
Batch Processing

Data processing dan ETL jobs dengan scheduled execution

  • Image/video processing
  • Data transformation
  • Report generation
Event-Driven Apps

Real-time response to system events dan user actions

  • File upload processing
  • Database change triggers
  • IoT data processing
Security Automation

Automated security responses dan compliance checks

  • Security scanning
  • Compliance validation
  • Incident response

Tugas Praktikum & Assessment

Tugas Implementasi Serverless Functions

Tugas 1: AWS Lambda

Implementasi image processing function:

  • S3 trigger untuk image upload
  • Image resizing dan optimization
  • Metadata extraction
  • DynamoDB storage
Nilai: 35%

Tugas 2: OpenNebula Functions

Setup serverless workflow di private cloud:

  • OneFlow service template
  • Custom runtime environment
  • Auto-scaling configuration
  • Monitoring integration
Nilai: 35%

Tugas 3: Performance Optimization

Optimasi performa dan biaya:

  • Cold start mitigation
  • Memory optimization
  • Cost analysis
  • Monitoring dashboard
Nilai: 30%

Deliverables & Timeline

Function Code
All platforms
📊
Performance Report
Metrics & analysis
💰
Cost Analysis
Pricing comparison
📝
Architecture Doc
Design patterns

Kriteria Penilaian

Function Implementation (50%)

  • Working serverless functions
  • Proper error handling
  • Event trigger configuration
  • Multi-platform compatibility

Performance & Optimization (30%)

  • Cold start optimization
  • Memory/CPU efficiency
  • Cost-effective design
  • Auto-scaling implementation

Documentation & Analysis (20%)

  • Architecture documentation
  • Performance metrics
  • Cost analysis report
  • Best practices implementation

Serverless Resources & References

Learning Materials

  • Serverless Architecture Patterns
  • Cold Start Optimization Guide
  • Cost Optimization Strategies
  • Security Best Practices