ebook img

Web Applications on Azure: Developing for Global Scale PDF

529 Pages·2018·13.75 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Web Applications on Azure: Developing for Global Scale

Web Applications on Azure Developing for Global Scale — Rob Reagan Web Applications on Azure Developing for Global Scale Rob Reagan Web Applications on Azure Rob Reagan Chattanooga, Tennessee, USA ISBN-13 (pbk): 978-1-4842-2975-0 ISBN-13 (electronic): 978-1-4842-2976-7 https://doi.org/10.1007/978-1-4842-2976-7 Library of Congress Control Number: 2017962632 Copyright © 2018 by Rob Reagan This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director: Welmoed Spahr Editorial Director: Todd Green Acquisitions Editor: Gwenan Spearing Development Editor: Laura Berendson Technical Reviewer: Fabio Ferracchiati Coordinating Editor: Nancy Chen Copy Editor: Teresa F. Horton Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail [email protected], or visit http://www.apress.com/ rights-permissions. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book's product page, located at www.apress.com/9781484229750. For more detailed information, please visit http://www.apress.com/source-code. Printed on acid-free paper For Brandi. Without your patience and encouragement, this book would not be possible. I love you. Table of Contents About the Author �����������������������������������������������������������������������������������������������������xv About the Technical Reviewer �������������������������������������������������������������������������������xvii Acknowledgments ��������������������������������������������������������������������������������������������������xix Introduction ������������������������������������������������������������������������������������������������������������xxi Chapter 1: Introducing Azure �����������������������������������������������������������������������������������1 What Is Azure? ������������������������������������������������������������������������������������������������������������������������������1 Cloud-Based Compute-on-Demand Services ��������������������������������������������������������������������������1 Infrastructure-as-a-Service vs� Platform-as-a-Service�����������������������������������������������������������2 Setting Up Your Machine for Azure Development �������������������������������������������������������������������������3 Visual Studio 2015 Community Edition �����������������������������������������������������������������������������������3 Azure SDK ��������������������������������������������������������������������������������������������������������������������������������4 SQL Server 2016 Express Edition �������������������������������������������������������������������������������������������4 SQL Server Management Studio �������������������������������������������������������������������������������������������12 Microsoft Azure Storage Explorer ������������������������������������������������������������������������������������������12 Redis Desktop Manager ��������������������������������������������������������������������������������������������������������12 Setting Up Your Azure Account ����������������������������������������������������������������������������������������������������13 Free Trial ��������������������������������������������������������������������������������������������������������������������������������13 Purchasing an Azure Subscription�����������������������������������������������������������������������������������������15 Enterprise Agreements ����������������������������������������������������������������������������������������������������������17 Summary�������������������������������������������������������������������������������������������������������������������������������������18 Chapter 2: Web Applications ����������������������������������������������������������������������������������19 Introducing the Verify App �����������������������������������������������������������������������������������������������������������20 Building the Verify Web Application ��������������������������������������������������������������������������������������������21 Creating the Database and Person Tables �����������������������������������������������������������������������������21 Creating the Web Application ������������������������������������������������������������������������������������������������22 v Table of ConTenTs Adding a SQL Server Database Project ���������������������������������������������������������������������������������23 Adding Entity Framework Core to Verify�Web ������������������������������������������������������������������������24 Generating the Entity Framework DbContext and Models Classes ����������������������������������������25 Creating the Service Layer ����������������������������������������������������������������������������������������������������26 Specifying Our Application Settings ��������������������������������������������������������������������������������������29 Setting Up Dependency Injection �������������������������������������������������������������������������������������������29 Adding the Front-End Controllers ������������������������������������������������������������������������������������������31 Deploying to Azure ����������������������������������������������������������������������������������������������������������������������33 Provisioning an Azure SQL Instance ��������������������������������������������������������������������������������������33 Deploying the Verify Database �����������������������������������������������������������������������������������������������37 Creating Our App Services Web App ��������������������������������������������������������������������������������������39 Publishing the Verify Application to Azure �����������������������������������������������������������������������������41 Scaling Web Apps ������������������������������������������������������������������������������������������������������������������������44 Intelligent Use of Threads ������������������������������������������������������������������������������������������������������44 App Service Plans ������������������������������������������������������������������������������������������������������������������45 Scaling Up �����������������������������������������������������������������������������������������������������������������������������46 Scaling Out ����������������������������������������������������������������������������������������������������������������������������47 Load Testing ��������������������������������������������������������������������������������������������������������������������������������51 Creating a Load Test ��������������������������������������������������������������������������������������������������������������52 Running the Load Test �����������������������������������������������������������������������������������������������������������55 Viewing Load Test Results �����������������������������������������������������������������������������������������������������55 Setting Appropriate Autoscale Rules �������������������������������������������������������������������������������������58 Summary�������������������������������������������������������������������������������������������������������������������������������������59 Chapter 3: Azure Data Storage Overview ���������������������������������������������������������������61 Data Storage Scenarios �������������������������������������������������������������������������������������������������������������61 Session Data ��������������������������������������������������������������������������������������������������������������������������62 Persisted Data �����������������������������������������������������������������������������������������������������������������������62 Data Analytics ������������������������������������������������������������������������������������������������������������������������63 Relational Databases ������������������������������������������������������������������������������������������������������������������63 Azure SQL ������������������������������������������������������������������������������������������������������������������������������65 Scaling Azure SQL �����������������������������������������������������������������������������������������������������������������66 vi Table of ConTenTs When to Use Azure SQL ���������������������������������������������������������������������������������������������������������68 Other Azure Relational Database Offerings ���������������������������������������������������������������������������68 NoSQL Data Stores ����������������������������������������������������������������������������������������������������������������������68 Redis Cache ���������������������������������������������������������������������������������������������������������������������������69 Azure Table Storage ���������������������������������������������������������������������������������������������������������������71 Cosmos DB ����������������������������������������������������������������������������������������������������������������������������������73 Working with Cosmos DB ������������������������������������������������������������������������������������������������������75 Scaling Cosmos DB ���������������������������������������������������������������������������������������������������������������75 Pricing �����������������������������������������������������������������������������������������������������������������������������������75 When to Use Cosmos DB �������������������������������������������������������������������������������������������������������76 Summary�������������������������������������������������������������������������������������������������������������������������������������76 Chapter 4: Azure SQL Databases ����������������������������������������������������������������������������77 Introducing Azure SQL Database ������������������������������������������������������������������������������������������������78 Licensing �������������������������������������������������������������������������������������������������������������������������������������80 Single Database vs� Elastic Pool ��������������������������������������������������������������������������������������������81 Exceeding a DTU Limit �����������������������������������������������������������������������������������������������������������81 TaskZilla: Our Example Application ���������������������������������������������������������������������������������������������82 Creating the TaskZilla Project ������������������������������������������������������������������������������������������������82 The TaskZilla Data Model �������������������������������������������������������������������������������������������������������84 The Data Access Tier �������������������������������������������������������������������������������������������������������������89 The Application Tier ���������������������������������������������������������������������������������������������������������������94 Controllers and Views ����������������������������������������������������������������������������������������������������������102 Finishing Touches ����������������������������������������������������������������������������������������������������������������107 Running the Application ������������������������������������������������������������������������������������������������������107 Deployment to Azure �����������������������������������������������������������������������������������������������������������������108 Creating an Azure SQL Database Instance ��������������������������������������������������������������������������109 Setting Firewall Rules ����������������������������������������������������������������������������������������������������������111 Connecting to the New Instance ������������������������������������������������������������������������������������������113 Deploying to Azure ��������������������������������������������������������������������������������������������������������������������114 Publishing Schema Changes ����������������������������������������������������������������������������������������������������122 Rolling Back Schema Changes �������������������������������������������������������������������������������������������������124 vii Table of ConTenTs Backup and Restore ������������������������������������������������������������������������������������������������������������������124 Setting Up Alerts �����������������������������������������������������������������������������������������������������������������������127 Scale Up ������������������������������������������������������������������������������������������������������������������������������������130 Performance Tuning ������������������������������������������������������������������������������������������������������������������131 Performance Recommendations �����������������������������������������������������������������������������������������131 Automating Performance Tuning �����������������������������������������������������������������������������������������132 Query Performance Insight ��������������������������������������������������������������������������������������������������133 Geo-replication��������������������������������������������������������������������������������������������������������������������������133 Summary�����������������������������������������������������������������������������������������������������������������������������������137 Chapter 5: Azure Table Storage ����������������������������������������������������������������������������139 How Table Storage Works ���������������������������������������������������������������������������������������������������������139 Partitions �����������������������������������������������������������������������������������������������������������������������������141 Transaction Support and Batching ��������������������������������������������������������������������������������������141 Types of Queries ������������������������������������������������������������������������������������������������������������������141 Working with Azure Table Storage ��������������������������������������������������������������������������������������������142 REST API ������������������������������������������������������������������������������������������������������������������������������142 Azure Storage Client Library �����������������������������������������������������������������������������������������������143 Local Storage Emulator �������������������������������������������������������������������������������������������������������143 Table Design Guidelines ������������������������������������������������������������������������������������������������������������144 Walkthrough: Restaurant Finder �����������������������������������������������������������������������������������������������145 Restaurant Finder Requirements �����������������������������������������������������������������������������������������145 Designing Our Data Storage ������������������������������������������������������������������������������������������������146 Setting Up the Project ����������������������������������������������������������������������������������������������������������147 Creating Our Restaurant Data Class ������������������������������������������������������������������������������������148 The Data Service Class ��������������������������������������������������������������������������������������������������������151 Project Settings �������������������������������������������������������������������������������������������������������������������156 Dependency Injection ����������������������������������������������������������������������������������������������������������157 Loading Demo Data with the RestaurantData Controller �����������������������������������������������������158 Azure Storage Explorer ��������������������������������������������������������������������������������������������������������161 Point Queries �����������������������������������������������������������������������������������������������������������������������162 Row Range Scan Queries ����������������������������������������������������������������������������������������������������165 viii Table of ConTenTs Partition Range Scan Queries ����������������������������������������������������������������������������������������������168 Full Table Scan Queries �������������������������������������������������������������������������������������������������������172 Editing a Restaurant ������������������������������������������������������������������������������������������������������������174 Deleting a Restaurant ����������������������������������������������������������������������������������������������������������178 Provisioning an Azure Storage Service��������������������������������������������������������������������������������179 Using Your Azure Storage Service ���������������������������������������������������������������������������������������184 Pricing ���������������������������������������������������������������������������������������������������������������������������������������185 Summary�����������������������������������������������������������������������������������������������������������������������������������185 Chapter 6: Cosmos DB ������������������������������������������������������������������������������������������187 Introducing Cosmos DB �������������������������������������������������������������������������������������������������������������188 Congo, the (Hopefully) Up-and-Coming Online Retail Giant �����������������������������������������������������189 Congo Requirements �����������������������������������������������������������������������������������������������������������190 Congo Tech Stack ����������������������������������������������������������������������������������������������������������������190 The Cosmos DB Resource Model ����������������������������������������������������������������������������������������������191 Partitions: How Cosmos DB Scales to Unlimited Storage ���������������������������������������������������������193 Data Modeling ���������������������������������������������������������������������������������������������������������������������������193 Determining Document Schemas ����������������������������������������������������������������������������������������194 Determining Partition Keys ��������������������������������������������������������������������������������������������������197 A Single Collection or Multiple Collections ��������������������������������������������������������������������������200 Using the Cosmos DB Emulator for Local Development �����������������������������������������������������������201 Creating a Collection in the Emulator ����������������������������������������������������������������������������������201 Importing Congo Data Using the DocumentDB Data Migration Tool ������������������������������������������205 Congo’s Initial Data ��������������������������������������������������������������������������������������������������������������205 Querying a Collection ����������������������������������������������������������������������������������������������������������������212 Creating the Congo Example Application ����������������������������������������������������������������������������������213 Creating the Project and Solution ����������������������������������������������������������������������������������������214 Creating the Model Classes �������������������������������������������������������������������������������������������������215 Creating View Model Classes ����������������������������������������������������������������������������������������������219 Creating the Home Page ������������������������������������������������������������������������������������������������������222 The Product Details Page ����������������������������������������������������������������������������������������������������234 Editing a Product �����������������������������������������������������������������������������������������������������������������237 ix Table of ConTenTs Retrieving All Reviews ���������������������������������������������������������������������������������������������������������240 Creating a New Review �������������������������������������������������������������������������������������������������������243 Deleting a Review ����������������������������������������������������������������������������������������������������������������246 Creating a Cosmos DB Account, Database, and Collection �������������������������������������������������������249 Scaling ��������������������������������������������������������������������������������������������������������������������������������������254 Summary�����������������������������������������������������������������������������������������������������������������������������������255 Chapter 7: Redis Cache �����������������������������������������������������������������������������������������257 The Cache Aside Pattern �����������������������������������������������������������������������������������������������������������259 Azure Redis Cache ��������������������������������������������������������������������������������������������������������������������260 Example Project: TechStore �������������������������������������������������������������������������������������������������������260 Creating the Project �������������������������������������������������������������������������������������������������������������261 Creating the Database ���������������������������������������������������������������������������������������������������������262 Adding Entity Framework ����������������������������������������������������������������������������������������������������268 Adding View Models ������������������������������������������������������������������������������������������������������������271 Creating the Service Layer ��������������������������������������������������������������������������������������������������274 Creating the Controller and Views ���������������������������������������������������������������������������������������278 Running the TechStore Application ��������������������������������������������������������������������������������������282 Create an Azure Redis Cache Resource ������������������������������������������������������������������������������284 Implementing the Cache Aside Pattern with Redis Cache ���������������������������������������������������285 Handling Stale Cache Records ��������������������������������������������������������������������������������������������294 Dealing with a Full Cache ����������������������������������������������������������������������������������������������������294 Setting Time-to-Live ������������������������������������������������������������������������������������������������������������295 Viewing Redis Cache Contents �������������������������������������������������������������������������������������������������295 Connect to a Redis Cache ���������������������������������������������������������������������������������������������������296 Viewing Cache Contents ������������������������������������������������������������������������������������������������������297 Flushing the Cache ��������������������������������������������������������������������������������������������������������������298 Scaling Azure Redis Cache �������������������������������������������������������������������������������������������������������298 Scaling Up ���������������������������������������������������������������������������������������������������������������������������299 Scaling Out ��������������������������������������������������������������������������������������������������������������������������299 Using Multiple Caches ���������������������������������������������������������������������������������������������������������299 Summary�����������������������������������������������������������������������������������������������������������������������������������300 x

Description:
Build .NET apps on Microsoft Azure services that can grow to Internet scale. Learn how you can make smart application architecture decisions and follow best practices so that your website can handle tens of thousands of concurrent users and deliver your content globally. Author Rob Reagan takes you
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.