Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pitfalls and Insights in Mastering Serverless API-Driven Architecture for Cloud-Native Apps.

Pitfalls and Insights in Mastering Serverless API-Driven Architecture for Cloud-Native Apps.

Explore the ups and downs of building cloud-native applications through a deep dive into serverless API-driven architecture. Discover common challenges, gain valuable insights, and learn the keys to achieving excellence in the dynamic world of cloud computing. Join us on this adventure as we simplify the complexities and highlight the best practices for mastering serverless API-driven architecture.

What are some core challenges?
Cost-related Challenges: Recognise the pitfalls and reasons for potential financial inefficiencies in API development by choosing the right services.
Data Processing Challenges: Understand the complexities associated with processing large datasets using serverless API solutions.
Scalability Concerns: Address potential challenges related to efficiently scaling serverless APIs.
Complex Debugging: Navigate through the complexities of debugging and monitoring serverless functions.

What problems does the session address and solve?
Cost-related Challenges: Learn how to build cost-effective solutions for API development.
Operational & Data Processing Best Practices: Gain insights into managing the operational complexities of a serverless API-driven architecture.
Scalability Challenges: Explore strategies for scaling serverless functions efficiently.
Development Challenges: Gain knowledge on solving challenges related to serverless development and troubleshooting.

Who is the target attendee?
Developers, architects, and tech enthusiasts engaged in API-driven ecosystems.

What can the attendee walk away with?
Learn from Mistakes: Understand how to solve complex problems and design API-driven architectures while considering key considerations.
In-Depth Insights: Gain profound insights into common pitfalls and best practices in serverless API-driven architecture.
Practical Guidance: Receive actionable advice on overcoming challenges and optimising your cloud-native setup.

Asif Waquar

April 17, 2024
Tweet

More Decks by Asif Waquar

Other Decks in Technology

Transcript

  1. 2 about me Asif Waquar Cloud Solution Architect |Singapore asifwaquar

    asifwaquar https://asifwaquar.com/ @asifwaquar
  2. Today’s Agenda Intro of Serverless API Driven Architecture Evolution of

    Serverless Architecture Application Types Key Benefits of Serverless Architecture Pitfalls of Serverless Architecture Best Practices Serverless API Driven Architecture
  3. Evolution of Serverless .. Increased focus on business logic Decreased

    concern (and control) over stack implementation Server Racks Virtual Machines Containers Functions
  4. Global Serverless Architecture Market Size, By Application, 2018-2032(USD million) •

    According to Gartner, the Global Serverless Computing Market, which stood at $9.3 billion in 2022, is projected to skyrocket to $90 billion by 2032, boasting a compelling CAGR of 20.8%.
  5. Key Benefits of Serverless API Driven Architecture Zero management/DevOps Auto

    Scaling Pay as you go (Cost Saving) Automated High Availablity
  6. Scenario 1 (Consumption Plan) Company X hosts a mobile application

    backend on Serverless Functions API. Initially, the application serves around 10,000 users per day, resulting in relatively low consumption costs. However, due to successful marketing campaigns and new feature launches, the user base rapidly grows, reaching 100,000 users per day within a few months. Higher Resource Consumption: For instance, inefficient database queries or poorly optimized algorithms can lead to higher resource consumption. • Initial daily cost: $100 • Cost after traffic surge: $150 (due to increased resource consumption) Scaling: After traffic surge: Scaling settings adjusted to be more aggressive, resulting in over-provisioning during non-peak hours. Monitoring and Optimization: •Lack of monitoring and optimization leads to sustained high costs even during periods of low traffic. •Additional resources are provisioned but not effectively utilized, resulting in wasted spending. Here's how the cost can burn if not managed effectively: In this scenario, without proper management and optimization, the company's monthly Azure consumption costs could increase by 50% or more as the user base grows. For instance: •Initial monthly cost: $3,000 •Cost after traffic surge: $4,500 (due to increased traffic, inefficient code, and scaling issues)
  7. Scenario 2 (Premium Plan) Company Y operates a mission-critical application

    that experiences unpredictable traffic spikes and requires low latency. They decide to migrate their Azure Functions to the Premium plan to ensure better performance and scalability. • Company Y starts with an estimated monthly cost of $621.08 for running their functions on the Premium plan. • Due to a sudden increase in demand or a marketing campaign, the application experiences a 200% surge in traffic compared to normal levels. As a result of the traffic surge and the Premium plan's enhanced performance features, the monthly cost rises to $12,421.68
  8. How do instances scale up and increase costs? Consider this

    example of how always-ready instances and prewarmed instances work together. A premium function app has two always ready instances configured, and the default of one prewarmed instance. When the app is idle and no events are triggering, the app is provisioned and running with two instances. At this time, you're billed for the two always ready instances but aren't billed for a prewarmed instance as no prewarmed instance is allocated. As your application starts receiving HTTP traffic, requests are load balanced across the two always-ready instances. As soon as those two instances start processing events, an instance gets added to fill the prewarmed buffer. The app is now running with three provisioned instances: the two always ready instances, and the third prewarmed and inactive buffer. You're billed for the three instances. As load increases and your app needs more instances to handle HTTP traffic, that prewarmed instance is swapped to an active instance. HTTP load is now routed to all three instances, and a fourth instance is instantly provisioned to fill the prewarmed buffer. This sequence of scaling and prewarming continues until the maximum instance count for the app is reached or load decreases causing the platform to scale back in after a period. No instances are prewarmed or activated beyond the maximum.
  9. Pitfalls of Serverless Debugging and Monitoring Serverless Functions : There

    are operational challenges such as monitoring, debugging, and troubleshooting serverless applications at scale. Timeout Error : Azure Function Timeout is difference depending on which hosting method / pricing tier is used to host an Azure Function App. It’s very hard to find out the root cause of the issue. Vendor Lock-In: With vendor lock-in , there are various risks including limited portability, dependency on proprietary services, and potential cost escalation. Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: AddProfileDataMethod ---> Newtonsoft.Json.JsonSerializationException : Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'. ---> System.InvalidOperationException : Timeouts are not supported on this stream. at System.IO.Stream.get_ReadTimeout()
  10. Lesson learned from previous experience • Limit Scale out Instances

    : Consider limiting the number of prewarmed instances and scaling out instances for autoscaling if you've opted for a Premium or App Service Plan. • Monitoring : For consumption-based plans, optimize code based on performance metrics and ensure proper monitoring. • Complex Logic :Avoid implementing large and complex logic within serverless functions, as it can make troubleshooting difficult. • Increase Timeout Period: Address timeout issues by updating the maximum timeout period in the host.json file or implementing logic such as Function chaining if you're utilizing Durable Functions. // Set functionTimeout to "No Limit" { "functionTimeout": "-1" }
  11. Best Practices Serverless API Driven Architecture • Performance Optimization: Regularly

    optimize code and resources to ensure efficient use of the Premium plan's features. • Monitoring and Scaling: Implement robust monitoring and scaling policies to dynamically adjust resources based on traffic patterns, preventing over-provisioning during traffic surges. • Cost Management: Utilize Azure Cost Management tools to set budgets, analyse spending trends, and identify areas for optimization. • Code Review : Conduct regular code reviews and optimizations to improve efficiency. Eg. Inefficient database queries or poorly optimized algorithms can lead to higher resource consumption. • Scale Settings: Fine-tune scaling settings to align with actual traffic patterns.
  12. Best Practices Serverless API Driven Architecture Before initiating any new

    application, it's crucial to conduct a thorough assessment. This ensures that the application aligns with the standards set forth by the Well-Architected Framework. To streamline this process, consider the following steps: Define Objectives: Clearly outline the objectives and requirements of the application. Understand the desired outcomes and the key performance indicators (KPIs) that will measure its success. Evaluate Architecture: Assess the proposed architecture against the pillars of the Well-Architected Framework: Operational Excellence, Security, Reliability, Performance Efficiency, and Cost Optimization. Ensure that the architecture supports scalability, fault tolerance, security best practices, and efficient resource utilization. Identify Risks: Identify potential risks and vulnerabilities in the application architecture and design. Evaluate how these risks may impact the application's performance, security, or cost-effectiveness. Review Compliance: Ensure that the application complies with relevant regulatory requirements and industry standards. Verify that data privacy, compliance, and governance measures are in place.
  13. Case Study • Smart Parking Management System." This system aims

    to optimize parking space utilization in urban areas by providing real-time information to drivers about available parking spots, reducing congestion and environmental impact. Operational Excellence: Serverless architectures abstract away server management tasks, enabling developers to focus on business logic. Automated scaling and managed services reduce operational overhead. Security: Serverless platforms like Azure Functions offer built-in security features, such as network isolation and automated patch management. Security controls can be implemented at various layers, ensuring data protection and compliance. Reliability: Serverless architectures inherently provide fault tolerance and automatic scaling, ensuring high availability and resilience to failures. Managed services like Azure Functions handle infrastructure management, reducing the risk of downtime. Performance Efficiency: Serverless architectures can scale dynamically to handle varying workloads, ensuring optimal performance even during peak times. Cost Optimization: With serverless architectures, you only pay for actual usage, making it cost- effective, especially for applications with fluctuating demand like a parking system. There are no upfront costs for provisioning or managing servers, and pricing scales with usage. Architecture Assessment: Given the objectives of the Smart Parking Management System and the need for scalability, reliability, and cost- effectiveness, a serverless architecture fits well. Here's why:
  14. Summary • Background of Serverless API Driven Architecture. • Benefits

    and Pitfall of Serverless API Driven Architecture • Best Practices to design Serverless API Driven Architecture.