Azure Functions 2.0 – 无服务器架构的实际用例

  • September End Announcement: In late September, Microsoft announced the general availability of Azure Functions 2.0. Excitement arose upon reading Eduardo Laureano's blog post about improvements and new features. Azure Functions 2.0 is production-ready with a 99.95 percent SLA and capable of handling demanding workloads. Altkom Software & Consulting decided it was time to test it deeper.
  • Why Serverless Matters: For years, software engineers aimed for low-coupled, high-cohesion systems but lost scalability and independence when deployed on one machine. Serverless allows for good design as components scale independently and meet their own performance and scalability requirements. It also eliminates the need to manage infrastructure like provisioning VMs and updating OSes. Serverless cloud takes care of these tasks and provides monitoring and auto-scaling features.
  • Azure Functions Features: Main features include the choice of language (C#, F#, Node.js, Java, PHP, batch, bash, or any executable), pay-per-use pricing model, bringing own dependencies (supports NuGet and NPM), integrated security (with OAuth providers), simplified integration (leverages Azure services and SaaS), flexible development (codes in portal or through various tools), open-source runtime on GitHub, and the possibility to deploy on-premise.
  • Business Use Case: Implemented a simple billing system in serverless architecture for a customer with subscription-based services. The system uploads a CSV file of beneficiaries to Azure Blob Container, triggering a function to generate billing items and send a message to an Azure Queue. Another function creates an invoice and sends messages to two queues. A third function generates a PDF using JsReport and saves it in Blob Storage, while a fourth function sends notifications via SendGrid and Twilio. Functions were created with best practices and tested in two approaches regarding function grouping.
  • Billing Items Generation: Parses uploaded CSV file, generates billing items using prices from an external database (CosmosDB), and saves them in an Azure Table. Triggered by BlobTrigger when a CSV file is uploaded with a specific name pattern.
  • Invoice Generation: Prepares and saves an invoice domain object in CosmosDB and sends information to queues for PDF generation and notification. Triggered by QueueTrigger when a message appears on the invoice-generation-request queue. Reads billing items from the table using CloudTable and a custom method.
  • Invoice Printing: Triggered by QueueTrigger when a message appears on the invoice-print-request queue. Delegates PDF creation to an external system (JS Report) and saves the PDF in Blob Storage using Binder.
  • Notifications Sending: Triggered by QueueTrigger when a message appears on the invoice-notification-request queue. Sends SMS and email notifications using built-in integrations with Twilio and SendGrid. Creates SendGridMessage and CreateMessageOptions objects with appropriate details.
  • Pricing: Pricing depends on execution time and memory consumption. Average execution times for functions were calculated, but there is no way to check memory consumption in Azure Functions 2.0. An Excel file was prepared based on documentation for pricing calculation. Approximately the first 130,000 calls are free, and limiting resource consumption to 256MB decreases the cost. Storage and network rates were omitted from the calculations.
  • Monitoring: Integrated with Azure Application Insight for good monitoring and easy issue diagnosis. In Functions 2.0, integration was expanded to provide more visibility into distributed tracing. End-to-end transaction details view helps monitor each execution.
  • Summary: Azure Functions 2.0 is production-ready. Pros include great developer experience, promotes better design, focuses on small components, has autoscaling and monitoring, pays only for used resources, eliminates infrastructure management, and has simple integrations. Cons include magical infrastructure risks, cold start problem, limited integration possibilities, lack of server app control, complex configuration, and imperfect cost control.
阅读 9
0 条评论