Microservices Anton Boyko Microsoft Azure MVP Ninja Azure
Microservices? Anton Boyko Microsoft Azure MVP Ninja Azure Consultant boyko. ant@live. com
Agenda • What and why? – What is microservice architecture approach and why should I care? • Several examples – Several examples of microservice architecture from real life projects • Implementation checklist – Several important points you need to consider while planning your microservice architecture • What about Azure? – What Microsoft Azure can offer for my microservices?
WHAT AND WHY?
Criteria Maintainability Monitoring Scalability • How easy is it to maintain the code? • How easy is it to fix a bug? • How easy is it to monitor solution health? • How easy is it to add new computin power and handle heavier load? Updates Onboarding • How easy is it to update solution to the newest version? • How easy is it to get onboard a new team member?
Spaghetti $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: ". $conn->connect_error); } $sql = "SELECT firstname, lastname FROM users"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo "<table>"; while($row = $result->fetch_assoc()) { echo "<tr><td>"; echo $row["firstname"]. "</td><td>". $row["lastname"]; echo "</td></tr>"; } echo "</table>"; } else { echo "0 results"; } $conn->close();
Spaghetti Maintainability Monitoring Scalability • Impossible • Almost impossible • Sometimes possible Updates Onboarding • Requires shutdown • Highly demotivating
Monolith • Application in which user interface and data access code are combined into a single program. • Design philosophy is that the application is responsible not just for a particular task, but can perform every step needed to complete a particular function.
Monolith Solution Presentation Application Data NLB Solution Server
Monolith Maintainability Monitoring Scalability • Mostly possible • Highly depends on solution size • Possible • Mostly possible Updates Onboarding • Requires shutdown • Possible • Highly depends on solution size
Microservices • Microservices is a variant of the serviceoriented architecture (SOA) architectural style that structures an application as a collection of loosely coupled services. • Microservices should be fine-grained and protocols should be lightweight. • Application is easier to understand, develop and test.
Microservices Microservice 1 Presentation Application Data NLB Microservice 2 Application Data Microservice 3 Presentation Server
Microservices Maintainability Monitoring Scalability • Possible • Highly depends on solution size • Possible Updates Onboarding • Can be handled without shutdown • Highly depends on solution size • Possible
Nanoservices • Nanoservices is a microservices anti-pattern where each service is too fine grained. • Nanoservice is a service whose overhead (communications, maintenance etc. ) outweighs its utility.
Nanoservices User login Get categories Get goods Get my orders Presentation Application Data User register Add category Get good by id Create order Presentation Application Data
Nanoservices Maintainability Monitoring Scalability • Almost impossible • Possible Updates Onboarding • Can be handled without shutdown • Extremely depends on solution size • Sometimes possible
microservices = architecture
microservices ≠ golden hammer
SEVERAL EXAMPLES
Online shop Identity Client Profile Admin Search Data Ad Social
Community portal Web Admin Rendering Data Member Notification Speaker Identity
IMPLEMENTATION CHECKLIST
Infrastructure components q. Microservices hosts q. Configuration source q. Routing and/or autodiscovery engine q. Monitoring engine q. Logging engine
CQRS • Synchronous queries – send request and wait for response with data – it’s acceptable to join data on a client side • Asynchronous commands – send request and wait for command unique id – use command id to check execution status – handling distributed transactions that affect several microservices can be tricky – commands should be idempotent
CAP theorem Consistency Availability Partitioning
Eventual consistency After command for data modification was received, it may take some time for new data to be available for querying write entity Client app write [ 42 ] API id = 42 Client cache DB
Eventual consistency After command for data modification was received, it may take some time for new data to be available for querying read list Client app read [ 42, 60 ] API [ 1, 20, 50, … ] Client cache DB
Eventual consistency After command for data modification was received, it may take some time for new data to be available for querying read list Client app read [ 60 ] remove [ 42 ] API [ 1, 20, 42, 50, … ] Client cache DB
WHAT ABOUT AZURE?
Azure Service Fabric • • Service Fabric itself is platform agnostic Stateless and statefull services Service discovery Health monitoring Fault domains and upgrade domains Enterprise-ready https: //docs. microsoft. com/enus/azure/service-fabric/
Fault and upgrade domains Fault 1 Update 1 Fault 2 Fault 3 Fault 4 Fault 5 Node 1 Update 2 Node 2 Update 3 Node 3 Update 4 Node 4 Update 5 Node 5 Main Primary reserved Secondary reserved Microservice 1 1 2 3 Microservice 2 2 3 4 Microservice 3 3 4 5 Microservice 4 4 5 1 Microservice 5 5 1 2
Azure App Services • • . NET, Java, PHP, Node. JS, Python Shared web farm, isolated web apps Configuration management Backups Sticky sessions Built-in My. SQL database https: //docs. microsoft. com/en-us/azure/appservice-web/
Azure App Services NLB Server 1 CPU App 1 root Server 2 RAM App 2 root CPU Server 3 RAM App 3 root CPU App 4 root RAM App 5 root Server 4 CPU RAM Distributed file system
Azure App Services NLB Server 1 CPU App 1 root Server 2 RAM App 2 root CPU Server 3 RAM App 3 root CPU App 4 root RAM App 5 root Server 4 CPU RAM Distributed file system
Azure Functions • Built on top of Azure App Services • Small and independent unit of work • Designed for handling huge amount of small parallel independent executions • Consider them as event handlers • Triggers and bindings • Can be chained to handle sequential workflow • Dedicated and consumption pricing plans • https: //docs. microsoft. com/en-us/azure -functions/
Azure Functions
Azure Functions bindings Type Service Trigger Input Output Schedule Azure Functions ✔ HTTP Azure Functions ✔ Blob Storage Azure Storage ✔ Events Azure Event Hubs ✔ ✔ Queues Azure Storage ✔ ✔ Queues and topics Azure Service Bus ✔ ✔ Storage tables Azure Storage ✔ ✔ SQL tables Azure Mobile Apps ✔ ✔ No-SQL DB Azure Document. DB ✔ ✔ Push Notifications Azure Notification Hubs ✔ Twilio SMS Text Twilio ✔ Send. Grid email Send. Grid ✔ ✔
Azure functions quickstart • Create cross-platform desktop apps using Java. Script and Azure https: //www. youtube. com/playlist? list=PLi 8 g art. Tl. TVx 7 s. Kg 3 XLu. CQik 1 XSg. UMNgl • Sql Saturday 2017 Kyiv https: //www. youtube. com/playlist? list=PLi 8 g art. Tl. TVx. R 9 l. GYAXUNTk 1 Mo 0 q. G 1 j 7 i
Questions? Anton Boyko Microsoft Azure MVP Ninja Azure Consultant boyko. ant@live. com
- Slides: 39