Building Cloud- Native Applications with Node.Js and Azure Ii
Total Page:16
File Type:pdf, Size:1020Kb
Azure E-book Series Building cloud- native applications with Node.js and Azure ii PUBLISHED BY Microsoft Press A division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2018 by Microsoft Corporation All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Support at [email protected]. Please tell us what you think of this book at http://aka.ms/tellpress. This book is provided “as-is” and expresses the author’s views and opinions. The views, opinions and information expressed in this book, including URL and other Internet website references, may change without notice. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred. Microsoft and the trademarks listed at http://www.microsoft.com on the “Trademarks” webpage are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. February Table of contents iii 2018 31 Azure Cosmos DB: Migrate an existing 01 Node.js MongoDB web app Introduction 32 Get set up 34 Connect and migrate 38 Next steps 04 39 Azure Database for MySQL: Use Node.js to connect and query data Chapter 1 / The basics of cloud-native 40 Get set up applications and Node.js 40 Prepare to connect 41 Connect and manipulate data 46 Next steps 06 47 How to use Azure Redis Cache with Node.js 48 Get set up Chapter 2 / The benefits of cloud native 54 Next steps for Node.js development 55 How to use Blob storage from Node.js 58 Store and retrieve blobs 07 Pillars of cloud-native applications with Node.js 63 Manage blob access 67 Next steps 08 Chapter 3 / Principles for architecting 68 your cloud-native applications Summary 09 Sample architecture 11 Before you get started 12 Chapter 4 / Build the app 13 Create a Node.js web app in Azure App Service on Linux 14 Before you begin 14 Get set up 18 Build and deploy 21 Update and manage 21 Manage your new Azure web app 24 Deploy an Azure Container Service (AKS) cluster 25 Get set up 26 Deploy and test 30 Finish up 30 Next steps February Introduction 1 2018 01 / This e-book The basics of cloud-native applications and presents a Node.js 02 / structured The benefits of cloud-native applications approach for for Node.js 03 / building Principles for architecting your cloud-native Node.js application with Node.js 04 / cloud-native How to build a cloud-native application applications with Node.js and Azure February Introduction 2 2018 Node.js and cloud-native applications are changing the way developers build February Introduction 3 2018 These services communicate through APIs Instead of or by using asynchronous messaging. Applications scale horizontally, adding new monoliths, instances as demand requires. applications are Node.js on the cloud / single threaded decomposed / event driven / increased execution speed into smaller, / designed for elastic scale automated self-management decentralized Traditional web servers / multi-threaded services / always-on / occassional bug updates / manual management / monolithic, centralized These trends bring new challenges. Application state is distributed. Operations are done in parallel and asynchronously. The system as a whole must be resilient when failures occur. Deployments must be automated and predictable. Monitoring and telemetry are critical for gaining insight into the system. February The basics of cloud-native applications 4 2018 and Node.js Cloud-native applications are ones that Chapter 1 / are designed specifically for a cloud computing architecture. These applications are designed to take advantage of cloud computing frameworks, which The basics of are composed of loosely coupled cloud services. Such applications are ones that cloud-native have a high degree of uptime and are highly available, from wherever there’s an applications and internet connection. These applications are Node.js extremely scalable. February The basics of cloud-native applications 5 2018 and Node.js In the simplest way to describe it, Node.js This makes Node.js a natural for the is server-side JavaScript. It’s non-blocking cloud, with its anywhere access and need and event-driven; thanks to its event for speed. With Azure, which is built to loop, it is optimized for handling support many architectures (including asynchronous I/O, such as calls to microservices), databases, and services, databases or external services, two very as well as having support for containers, common operations in modern web Node.js is all the more powerful. For apps. And, because it’s JavaScript, it’s fast example, on Azure it’s easy to add identity and flexible to use with other types of and access management through Azure code. JavaScript was originally designed Active Directory, vision and speech as a language only for client-side web capabilities with Azure Cognitive Services, applications, but Node.js allows for server- or data insights through Azure Data Lake side development, making it one of the Analytics – just to name a few of the most popular programming languages. many examples. Node.js allows web developers to expand their creative potential by creating servers, command-line tools, and desktop applications. Using asynchronous I/O, the server can do more than one thing at a time, a key requirement for real-time apps like chat, games and live statistics. February The benefits of cloud-native for Node.js 6 2018 development Application development and IT system Chapter 2 / management is undergoing revolutionary change driven by the cloud. Fast, agile, inexpensive, and massively scalable infrastructure is improving operational The benefits efficiency and enabling faster-time-to- value across industries. The emergence of cloud native of containers, with their fast startup, standardized application packaging, for Node.js and isolation model, is further contributing development to efficiency and agility. There are many ways businesses can take advantage of the capabilities this brings. Quick and reliable data processing, error analysis, and quick code deployment can enable a startup to grow faster than larger companies. You can reduce build times and user customization enabled by using Node.js when streaming content. Companies can also align dispersed development teams onto a single language with Node.js, which means significantly less time is spent writing code. Azure cloud services provide Node.js developers the ability to quickly add new functionality to their software while remaining stable and secure in production. By using Azure cloud services, you can develop, package, deploy and scale powerful applications on many of platforms. February The benefits of cloud-native for Node.js 7 2018 development Flexibility with components Pillars of Azure supports many architectures, operating systems, tools, services, and cloud-native databases. Because of this, Node.js developers can connect to the functionality applications they need to support their applications: databases, identity providers, cognitive with Node.js services, etc. Reliability As more and more applications are being Azure offers a large variety of hosting developed in the cloud, agile practices have options, including Linux and Kubernetes. emerged. Agile development promotes With containers like Docker you can small, well planned, iterations by highly develop new features and functionality collaborative teams, resulting in continuous within the production environment, but delivery. The pillars of agile methodology isolate them so that you can test and roll likely fit well with why you chose to work out new features or fixes with confidence. with Node.js in the first place. Some of the greatest benefits of working Speed in the cloud are the monitoring and Deliver the responsiveness users demand. analytics capabilities. By tracking costs Because Node.js runs on the Chrome V8 and efficiencies of your work, you can engine, which is optimized for speed, and understand what is working well, and make because of its asynchronous processing, better decisions. This will also allow you to Node.js apps are very fast. With Node.js, simplify your environment and free speed is also about development agility, up resources. which using JavaScript enables. Lastly, with around half a million modules (and counting) on NPM, the Node.js Package Manager, developers can easily integrate libraries for many common tasks. February Principles for architecting your 8 2018 cloud-native application In this section, we will walk through Chapter 3 / the process of creating, hosting, and architecting your cloud-native application. The architecture in this chapter includes the core components available to you as Principles for a Node.js developer using Azure to build fast, reliable, and flexible applications in architecting your the cloud. With the cloud you get to pick and choose what services you use to build cloud-native your application. Depending on your business logic you will probably use some application combination of the following; Web Apps on Linux, Kubernetes, CosmosDB (MongoDB), MySQL/PostgreSQL, Redis Cache, Blob storage. February Principles for architecting your 9 2018 cloud-native application Kubernetes on Azure Container Service With the cloud (AKS) Azure Container Service (AKS) offers a fully- you get to pick managed Kubernetes cluster. You can pick and choose the number and kind of worker and choose what nodes you want, and Azure takes care of provisioning, managing and updating services you use them, giving you access to a full Kubernetes cluster that can be interacted with using the to build your web UI or kubectl. application Cosmos DB (MongoDB) Cosmos DB is a managed, massively scalable, NoSQL Database-as-a-Service Web apps on Linux available on Azure, that offers full protocol Modern cloud-native applications usually compatibility with MongoDB.