1 Cloud Hosting Options 2 Cloud Hosting in Microsoft Azure 4 Building Applications in Azure 30 Building a Mobile App in Azure 45 Utilizing Azure for a Desktop Application 48 Internet of
Trang 1What Programmers Need to Know about Microsoft’s Cloud Platform
Azure for
Developers
John Adams
Trang 2Free Webcast Series
Learn about popular programming topics from experts live, online
Trang 4John Adams
Azure for Developers
Trang 5[LSI]
Azure for Developers
by John Adams
Copyright © 2015 O’Reilly Media, Inc All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://safaribooksonline.com) For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editor: Brian MacDonald
Production Editor: Nicole Shelby
Copyeditor: Rachel Head
Proofreader: Christina Edwards
Interior Designer: David Futato
Cover Designer: Randy Comer
Illustrator: Rebecca Demarest May 2015: First Edition
Revision History for the First Edition
Trang 6Table of Contents
Preface v
Microsoft Azure for Developers 1
Cloud Hosting Options 2
Cloud Hosting in Microsoft Azure 4
Building Applications in Azure 30
Building a Mobile App in Azure 45
Utilizing Azure for a Desktop Application 48
Internet of Things Service 50
Conclusion 52
Trang 8Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and fileextensions
Constant width
Used for program listings, as well as within paragraphs to refer
to program elements such as variable or function names, data‐bases, data types, environment variables, statements, and key‐words
This element signifies a tip or suggestion
Using Code Examples
This book is here to help you get your job done In general, if exam‐ple code is offered with this book, you may use it in your programsand documentation You do not need to contact us for permissionunless you’re reproducing a significant portion of the code Forexample, writing a program that uses several chunks of code fromthis book does not require permission Selling or distributing a CD-ROM of examples from O’Reilly books does require permission.Answering a question by citing this book and quoting example code
Trang 9does not require permission Incorporating a significant amount ofexample code from this book into your product’s documentationdoes require permission.
We appreciate, but do not require, attribution An attribution usu‐ally includes the title, author, publisher, and ISBN For example:
“Azure for Developers by John Adams (O’Reilly) Copyright 2015
O’Reilly Media, 978-1-491-92612-3.”
If you feel your use of code examples falls outside fair use or the per‐
sions@oreilly.com
Safari® Books Online
Safari Books Online is an on-demand digital library that deliversexpert content in both book and video form from the world’s lead‐ing authors in technology and business
Technology professionals, software developers, web designers, andbusiness and creative professionals use Safari Books Online as theirprimary resource for research, problem solving, learning, and certif‐ication training
Safari Books Online offers a range of plans and pricing for enter‐prise, government, education, and individuals
Members have access to thousands of books, training videos, andprepublication manuscripts in one fully searchable database frompublishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press,Focal Press, Cisco Press, John Wiley & Sons, Syngress, MorganKaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress,Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Tech‐
Books Online, please visit us online
Trang 10How to Contact Us
Please address comments and questions concerning this book to thepublisher:
O’Reilly Media, Inc
1005 Gravenstein Highway North
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
Trang 12Microsoft Azure for Developers
By now, you have certainly heard of the cloud Many major compa‐nies are using cloud computing today to power websites, mobileapps, and business software on a massive scale and can normallyeven save some money while doing it Amazon, Google, and Micro‐soft have all released cloud computing platforms over the last decadethat are designed to host software and services that were tradition‐ally run out of a company’s own private data centers Amazon wasthe first to get started and is still probably the biggest supplier ofcloud-hosted virtual machines in the world Google and Microsoftlaunched their own platforms a few years later and have developedand grown them in unique directions Google’s cloud platform offersseveral hosting options and some unique and powerful big dataNoSQL services Microsoft Azure, interestingly, has adopted themost pluralistic approach to the cloud and embraces developmentusing a wide range of programming frameworks, operating systems,and third-party services, so that a company can move its entire tech‐nology structure into the cloud regardless of the technologies itdepends on
These cloud platforms have enabled businesses and developers toevolve their applications in ways previously unavailable and unfeasi‐ble This report will explore Microsoft’s cloud platform, MicrosoftAzure, and take you through the basics of the platform and its com‐ponents, on into some examples of how to properly use it for yourown software solutions As you can imagine, Microsoft Azure hasdozens of features that run the full spectrum of IT services, but wewill focus here specifically on the parts of Azure you can use as adeveloper to build your applications in the cloud
Trang 13Cloud Hosting Options
Before we get into the specifics of Microsoft Azure, let me introducethe basics of what cloud hosting means In order to use the cloud foryour own applications, you have to choose how you want your code
to be hosted by the cloud platform There are three distinct hostingoptions for your apps that can be arranged on a scale of how muchresponsibility lies with you versus how much responsibility lies withthe cloud hosting provider:
• Infrastructure as a Service (IaaS)
• Platform as a Service (PaaS)
• Web hosting
When you consume a hosted service that someone else is providing,
it is known as using “Software as a Service” (SaaS) Each of thesehosting options requires a certain amount of responsibility fromyou and a certain amount of responsibility from the cloud platformprovider The following table shows how they break down in thesecategories Each of these categories and terms will appear through‐out the rest of this report
Infrastructure as a Service
IaaS hosting is a way to lease your hardware from a data center inthe form of virtual machines and virtual networks This might bewhat you think of first when you hear discussions about the cloud
In this model, it is your responsibility to maintain the operating sys‐tems and software that run on top of this leased infrastructure Vir‐tual machines can often be selected from a gallery of preconfiguredimages with different operating systems, or you can upload yourown images if you have them As your application grows, you canscale it by moving it onto more powerful hardware (known as “scal‐ing up” or “scaling vertically”) or by allocating more instances ofyour virtual machines onto more servers (known as “scaling out” or
“scaling horizontally”) Scaling either way will increase your costs, of
Trang 14course, since you are using either better or more leased hardware.You can even sometimes configure the cloud-hosting platform toautomatically scale both up and down based on your own criteria,such as when CPU and memory use peak or drop to certain points.
Platform as a Service
PaaS hosting moves you up one level higher in the stack so that yourlowest level of concern is software instead of an operating system.This is my favorite cloud hosting model because it relieves develop‐ers of DevOps responsibilities like managing operating systempatches and virtual machine images, while providing automaticdeployment of application code and allowing us to retain completecontrol over our own software and its environment
In this model, you create your application code and then deployyour app to managed virtual machines that run your code automati‐cally You can scale these virtual machines up or out, just as in IaaS,
in order to serve more concurrent users You can still normallyaccess the operating system, but you are not responsible for instal‐ling or maintaining it Instead of leasing hardware that runs yourvirtual machines, like with IaaS, you are leasing virtual machinesthat run your code
However, you normally do not have as many operating systemchoices here as with IaaS Since they are managing the service, thecloud provider likely only supports a small set of operating systemsfor use by your application code and a specific set of supported pro‐gramming frameworks that your application can utilize You’ll want
to make sure the programming framework you want to use is sup‐ported before you make an investment here
Web Hosting
Web hosting is a model where you lease a spot on a web server thathosts your application files Instead of initially leasing full servers orvirtual machines, you lease a managed directory on a multitenantweb server and access your own files through FTP By giving upcontrol over the operating system and web server software, you gain
a simpler interface to your application and pay less for what you areusing You have a lot less responsibility for maintaining various lev‐els of the programming stack, but you simultaneously give up somecontrol and flexibility
Trang 15This is often a great way to get started with a cloud-hosted webapplication, where costs are lower and implementation is simpler Ifyour app expands and ends up needing dedicated servers, you canoften scale it up to that point or even migrate it to the PaaS model,where you can allocate more dedicated and specialized hostingpower.
Cloud Hosting in Microsoft Azure
Microsoft Azure offers hosting options in all three categories IaaShosting is offered through Azure Virtual Machines, PaaS hosting isoffered primarily through Azure Cloud Services, and web hosting isoffered through Azure Web Apps as part of a newly redesignedAzure App Service Azure also provides a full suite of Microsoft andthird-party SaaS services designed to scale alongside your apps.These SaaS services include such things as file storage, databases,message queueing, authentication and authorization, Internet ofThings (IoT) event processing and stream analytics, machine learn‐ing, big data analysis, search, mobile app push notifications, contentdelivery networks, job schedulers, and more
In Microsoft Azure terms, these services are broken down into two
main groups: compute and storage Compute-based services are so
named because consumption in this area is based primarily on pro‐cessor cores and memory per unit; this includes all forms of cloudhosting, machine learning, job schedulers, and so on Storage-basedservices are consumed in terms of capacity and throughput andinclude the obvious file storage and databases but also messagequeueing, IoT services, and others On the Microsoft Azure websitethese services may be grouped into other smaller categories, but youcan see the difference when you look at how they are billed andscaled Let’s take these two categories and explore what MicrosoftAzure has to offer in each one
Compute
As we just discussed, compute-based services include all forms ofcloud hosting and some other related features Even though the dif‐ferent hosting options are unique, you are completely free to mixand match them to suit your application needs A single solutioninside of Microsoft Azure could easily use all three hosting models
Trang 16We’ll start by exploring the three hosting models (Virtual Machines,Cloud Services, and App Service) in more detail.
Virtual Machines (IaaS)
If you want a bare server with only an operating system or if youalready have a virtual machine image you want to host inside thecloud, Azure virtual machines are what you need
If you don’t already have an image and you want a fresh system, youcan choose from various versions and editions of Windows Server,Ubuntu, CentOS, CoreOS, OpenSUSE, Oracle Linux, SUSE LinuxEnterprise, and more More options are being added every month,
in fact If you want a virtual machine prepackaged with licensedsoftware you can use right out of the box, Azure offers a gallery ofpreconfigured systems (see Figure 1-1) There are dozens of existingimages you can choose from and have running in minutes Thechoices here are very broad: they include database servers like SQLServer, Oracle, Hadoop, Couchbase, and others; NAS and securitydevices; application servers like IBM WebSphere and Jenkins; andSysOps tools like Puppet and Docker More are being added all thetime, and it is likely that if you want a specific type of server on avirtual machine, Azure already has an image ready for you to use It
is as simple as click and go
Maybe you already have a production application that you want tomove off of your own data center, but you don’t want to rearchitectyour app for a different type of hosting In this model, you can takethe images of your existing Windows and Linux virtual machinesand upload them into Microsoft Azure as they are To do this, youneed to create disk space for them in Azure storage and upload thevirtual machine images using PowerShell; then you can find yourimages in the gallery, where you can create instances of them withthe hardware configurations you like This is an advanced process,and you can find full instructions in the Azure documentation
Trang 17Figure 1-1 A small sample of the Azure Virtual Machines gallery
Virtual machine disk drives are basically virtual hard drives stored
as page blobs (more on that later) within Azure storage Azure alsosupports network drives that can be mounted to your server instan‐ces through a service called Azure Files Azure Files drives can beaccessed by more than one machine at a time and are billed at a sep‐arate rate Either way, you should be able to configure your virtualmachines as you need them with some combination of these drivetypes
When you create an instance of a virtual machine, you have tochoose the tier of hardware on which to deploy it The price breaksdown based on the specifications of each hardware configuration.There are two general categories, Basic and Standard The Basic vir‐tual machines are designed to handle basic workloads They do notsupport load balancing, autoscaling, or any high memory configura‐tions These machines are available in the configurations listed in
Table 1-1
Trang 18Table 1-1 Basic virtual machine specs
Tier Cores Memory Disk
Table 1-2 Standard virtual machine specs, A series
Tier Cores Memory Disk
Trang 19tems They feature a 60% faster CPU, solid-state drives (SSDs) forlocal storage, and high memory configurations (see Table 1-3).
Table 1-3 Standard virtual machine specs, D series
Tier Cores Memory SSD
Table 1-4 Standard virtual machine specs, G series
Tier Cores Memory SSD
Cloud Services (PaaS)
If you are architecting a new application for the cloud instead ofusing existing virtual machine images, then Cloud Services is a goodoption for you This cloud hosting model maximizes your scalability
by automatically deploying your application onto a server and man‐aging its life cycle (for example, by auto-recycling the server if yourapplication fails for some reason), but also giving you a lot of access
to the underlying virtual machine Cloud service servers are accessi‐ble through the Remote Desktop Protocol (RDP) They support
Trang 20applications written in NET, Java, PHP, Python, Node.js, and Ruby.Cloud services can be implemented in two forms: web roles andworker roles.
Web roles are servers that have IIS enabled and are able to start aweb application within IIS as part of their startup process Since thisrole type is designed specifically to host a web application, it doesnot start receiving traffic from the Azure load balancer until the webapp in IIS is actually running too Likewise, if the application in IIScrashes for some reason, the web role will be taken out of serviceand recycled For web roles specifically, the difference betweenCloud Services and Azure App Service web hosting (more on thatlater) is that web roles give you remote desktop access and allow you
to install additional services onto the virtual machines
Worker roles are designed to run applications more similar to con‐sole apps or Windows services They are kicked off inside of aninfinite while loop in a method called Run() If this method everreturns—for example, if an exception is thrown—then the cloud ser‐vice knows to take the instance out of service and recycle it automat‐ically Worker roles can still communicate across the network, ofcourse, and they can even host web applications, but you will need
to configure the hosting yourself since they won’t be auto-deployingyour apps to IIS
Cloud services also come with built-in support for staging deploy‐ments onto a temporary DNS name and IP address so that you canverify that your changes are stable before you replace your runninginstances with new ones If the staged instances look good, you canswap them with your current production instances with a singleclick and your users will start hitting your new instancesautomatically
Microsoft has announced a new PaaS hosting option,
currently in preview, known as Azure Service Fabric It
is an advanced service that can host both stateless and
stateful applications (unlike cloud services, which are
all stateless) It also features new capabilities including
self-healing, auto-updating, and new orchestration
options You should investigate the Microsoft Azure
website and the BUILD 2015 recorded sessions to learn
the most up-to-date information
Trang 21Cloud services are billed at rates very similar to virtual machines.All cloud service servers are Windows servers; there is not a Linuxoption yet The A series cloud service servers (Table 1-5) aredesigned for normal workloads, though they do support some high-memory options Just like with virtual machines, the A8 and A9 tieroptions are optimized for massive network throughput with the 40Gbit/s network connection Likewise, the A10 and A11 options arespecialized for compute-intensive workloads and come with IntelXeon E5 processors
Table 1-5 Standard machine cloud service specs, A series
Tier Cores Memory Disk
Table 1-6 Standard cloud servce specs, D series
Tier Cores Memory SSD
D1 1 3.5 GB 50 GB
D2 2 7 GB 100 GB
D3 4 14 GB 200 GB
D4 8 28 GB 400 GB
Trang 22Tier Cores Memory SSD
D11 2 14 GB 100 GB
D12 4 28 GB 200 GB
D13 8 56 GB 400 GB
D14 16 112 GB 800 GB
App Service (web hosting)
Azure App Service is a new bundled hosting option that includesfour specific features: Web Apps, API Apps, Mobile Apps, and LogicApps You don’t have to use all four of the pieces—you can even usejust one By bundling them together, though, Microsoft provides theservice as a unit, so you don’t need separate billed services; this alsomakes it easier to combine them together to build a rich applicationsince they share a common framework
Azure App Service components (such as individual websites, mobileapps, etc.) are grouped into app service plans within the Azure por‐tal These app service plans can contain a single component on up to
as many as your pricing tier will allow Think of an app service plan
as a web application with all of the different URLs and pieces itmight be composed of grouped together inside For example, youmight have a website for your main public site, a secured website foradministration, a mobile app, and a public API Since these are allpart of the same overall app, it makes sense to group them under asingle app service plan and serve them together on the same virtualmachines; Azure will then deploy them together and scale themtogether The pricing tiers for Azure Web Apps are actually based onapp service plans, and all of the components within an app servicewill share the resources granted by the pricing tier that containsthem
Unlike the IaaS and PaaS options, Azure App Service has a Free ser‐vice tier You can run up to 10 apps per global region completelyfree, except for any costs you might incur through other optionalservices like storage or databases The Free tier lacks scaling andother advanced features, but it gives you a completely free way toexperiment within Microsoft Azure and to test out your ideas andconcepts You’re even allowed to start a production system in theFree tier and then scale it up once you need more power
Trang 23Azure App Service is billed in five tiers offering increasing amounts
of dedicated resources and features The billing structure for Azurewebsites is more complex than for cloud services or virtualmachines, but it basically breaks down as shown in Table 1-7 TheBasic, Standard, and Premium tiers provide dedicated virtualmachines for your websites, so they are billed not only by the tierbut also by the size of the virtual machine The Shared tier does not
provide dedicated machines, so it is billed per site at an hourly rate.
Table 1-7 Azure App Service specs by tier
Tier Max storage Max VMs
Every web app can take advantage of great developer featuresincluding remote debugging and continuous integration (CI) Webapps can be remotely debugged directly from within Visual Studio,
so you can step through code as it runs in the cloud Each web appproject can also tie into several common source code repositories,such as GitHub, Bitbucket, and Visual Studio Online, for CI featureslike automatic builds and deployments when changes are commit‐ted Of course, many different IDE tools are also supported, so youcan use the tools you like best to build your app in the Azure cloud.The Azure App Service tier you select has specific implications foryour web apps The five tiers differ in terms of network bandwidth,number of concurrent connections, and support for features likeSSL and custom DNS names as outlined in Table 1-8 These specifi‐
Trang 24cations are calculated per site for the Free and Shared tiers and per
virtual machine for the Basic, Standard, and Premium tiers In the
table, “WS” stands for web socket concurrent connections
Table 1-8 Azure Web App specs by App Service tier
Free 60 min/day 1 GB 5 No No
Shared 240 min/day 1 GB 35 Yes No
Basic 1, 2, 4 cores 1.75, 3.5, 7 GB 350 Yes Yes
Standard 1, 2, 4 cores 1.75, 3.5, 7 GB ∞ Yes Yes
Premium 1, 2, 4, 8 cores 1.75, 3.5, 7, 14 GB ∞ Yes Yes
The Standard and Premium tiers have exclusive options for dedica‐ted staging environments, some included SSL configuration, and sitebackup options Each Standard tier website gets five dedicated stag‐ing environments for application life cycle management and testing,and each Premium tier app gets 20 For example, you could deployyour code changes to a “develop” environment and then promotethat code to other environments when ready
In addition to all of this, Azure App Service has a rich marketplacefull of existing website packages you can immediately deploy anduse Here you will find dozens of well-known platforms coveringcontent management systems (CMS), ecommerce, wikis, collabora‐tion, blogs, starter sites, and more Most of these marketplace galleryoptions are free and open source, so you can host your own systemand use it however you want Any related resources, such as a data‐base server, will be automatically listed and configured for you
Azure App Service WebJobs WebJobs is a feature of Azure App Ser‐vice that gives you the ability to run scripts or executable programscontinuously or on a custom schedule to do work in the backgroundfor your app These WebJobs enable your app to run code independ‐ently of any requests from clients This is perfect for batch jobs,long-running tasks, cleanup work, queue processing, image process‐ing, etc.—the type of work you would normally offload from a webserver anyway
WebJobs can be uploaded to your Azure App Service in the Azure
portal and can be written as cmd, bat, exe, ps1, php, py, or js files.
You can also create WebJobs through a NuGet project template in
Trang 25Visual Studio and write them as normal NET projects The NuGetpackages for the WebJobs template give you easy access to commonAzure components, such as storage accounts with blobs and queues,without even having to write much code If not run continuously,WebJobs can respond to events, such as queue messages appearing
or blobs being added to a container, and run on demand You essen‐tially get an optimized worker role for free, and WebJobs can even
be written in a language to match your app’s code platform
Azure App Service API Apps API Apps is a new offering from Micro‐soft as part of Azure App Service Web Apps is to websites as APIApps is to HTTP-based API projects The only real differencebetween these services is that API apps are designed to be consumed
in a different way than web apps Just like web apps, your API appscan be built using NET, Java, Node.js, PHP, and Python
The special features of API apps come in the form of metadata man‐agement, gallery listings, and access control For metadata manage‐ment, each API app gets autogenerated documentation on API end‐points and HTTP verbs (through Swagger) with a web-based editorand URL-rewriting abilities Visual Studio can use this metadata toautogenerate REST client code, much like it does for Web ServicesDefinition Language (WSDL) services, for easy consumption Onceyou have deployed an API app to Azure, you can choose whether tolist that API publicly in the gallery or keep it private within yourown app service
Azure App Service Mobile Apps Mobile Apps is a special platform thatMicrosoft created to power mobile applications on any device Fromthe portal, you can download ready-made project templates to buildyour client-side app so that it automatically connects to this back‐end Mobile Apps will host your data in an easy format that can bemanaged from the portal, and will also host your backend serverlogic It supports push notifications, offline sync, enterprise singlesign-on, social integration, mobile analytics for your app, andautoscaling Mobile Apps is a straightforward way of adding amobile app for your site hosted in an Azure app service
Azure App Service Logic Apps Logic Apps is another new offeringfrom Microsoft as part of Azure App Service These apps are veryinteresting because nothing like this has been available on MicrosoftAzure before A logic app is a graphically configured workflow pro‐
Trang 26cess that pipes data between API apps (and other special connectorsavailable in the marketplace, some of which can be seen in
Figure 1-2) based on triggers and timers
Figure 1-2 Some connectors already available for Logic Apps
Essentially, this type of app lets you compose an integration work‐flow between your own API apps, third-party web services, andenterprise systems in a web-based editor I think the real benefithere is integration Imagine, for example, a trigger that responded to
a picture being added to a Dropbox folder that then sent a tweet; orimagine that when a new customer is added into a customer rela‐tionship management system an email is generated to a group ofemployees, a post is added to Yammer, and a welcoming text mes‐sage is sent to the customer from the business
Storage
Applications of every type need to store and manage data MicrosoftAzure offers a wide range of storage types, including files, queues,service bus relays and subscriptions, NoSQL databases like key/value stores and document stores, a managed SQL database,
Trang 27Hadoop, Redis, and more These are all available with guaranteedlevels of performance and throughput You can use any combination
of these storage types to power your applications, even if your appli‐cations are not hosted inside of Microsoft Azure; nearly all Azureservices are publicly exposed through a REST API and can be used
by apps inside or outside of Azure data centers
When Microsoft Azure first launched years ago, it included a stan‐dard storage account service Every one of these storage accountsincluded three elements: blob storage, table storage, and queue stor‐age Each of these received its own URL and security keys for access.Azure still includes this standard storage account option today, andthis is what I am referring to when I mention an Azure “storageaccount.”
Each storage account can contain a maximum of 500 TB of dataacross its three component parts (tables/blobs/queues) The data in
an Azure storage account is not backed up, per se, but it is alwaysstored in multiple copies so that it is still available in case of a hard‐ware or network failure An account can be configured with a morerobust data copying model, but the cost goes up a bit since thesecopies start to take up a lot more space The four data copying mod‐els available are listed in Table 1-9
Table 1-9 Azure storage data redundancy models
Redundancy model Features
Locally Redundant Storage (LRS) 3 copies, same data center
Zone Redundant Storage (ZRS) 3 copies, multiple centers in same region
Geo-Redundant Storage (GRS) LRS + 3 copies in different region
Read-Access GRS (RA-GRS) GRS + read access to other region during failure
If your application needs to exceed the limits imposed on Azurestorage accounts, the simplest solution is often to split the dataacross multiple accounts Each Azure subscription can allocate 100storage accounts, and you can probably get more if you contactMicrosoft There are also upper limits on the amount of requests persecond for different types of storage; check the Azure website forcurrent details
Any data going into an Azure data center, also known as “ingress,” isnot charged for bandwidth costs All data being sent out of an Azure
Trang 28data center, also known as “egress,” is charged for bandwidth Egresscosts are very low, but every form of data transfer is included andcharged; this includes downloads from blob storage, traffic fromweb servers, database access, and so on However, you should be
aware that traffic within Azure data centers is free, so you won’t be
charged for the traffic between your web server and your database,for example, if they are both inside of Microsoft Azure
In addition to the standard Azure storage account, there are severalother services that are now available We cover several of these in thefollowing sections, including file storage, message-based storage,NoSQL storage, SQL database storage, and Redis
File storage
Azure provides three different ways to store files: Blob Storage,Azure Files, and a content delivery network (CDN) Blob Storage ispart of the standard Azure storage account service; Azure Files andCDN are separate services
Blob storage Blob Storage is a simple service for storing data as files(if you haven’t heard the term “blob” before, it stands for BinaryLarge OBject) It can store a very large number of files per account,and it can store individual files that are very large Blob Storageorganizes files within containers, like folders, and can apply specificpermissions to the contents of these containers to limit access tothem The Blob Storage APIs allow for parallel uploads of binarydata so that large files can be uploaded as quickly as possible acrossthe Internet Files inside of Blob Storage can be created in one oftwo ways: as block blobs or as page blobs These two blob types haveunique features and purposes
Block blobs are the most common type and are designed for all nor‐mal file operations Block blobs are designed to be accessed as a sin‐gle unit, like in a file download They are a good choice for files thatneed to be accessed across the Internet, such as website images oruser-uploaded content; for storing a large number of potentiallylarge files with low cost, such as log files or videos; and also as alocation to persist data that a transient application, like a cloud ser‐vice, might need between sessions
The page blob is a special type of file that supports nonsequentialreads and writes, such as are necessary for virtual hard drives Thisblob type has its own limits and performance metrics As an inter‐
Trang 29esting note, page blobs are actually used to provide the local disksfor Azure Virtual Machines.
Azure files Azure Files is a special storage service designed to act as
a mountable virtual hard drive for Azure Virtual Machines andCloud Services It operates over the Server Message Block (SMB)protocol, and more than one Azure virtual machine or cloud servicecan use it simultaneously Azure Files is the ideal solution for creat‐ing persistent data drives for cloud services, especially if you want allinstances of the cloud service to access the same files in the samelocation and Blob Storage does not meet your application require‐ments
Azure CDN Azure also provides a globally available content deliverynetwork to help you boost the performance of web applications forcustomers around the country and around the world Azure CDNcan be enabled either for a public container in a Blob storageaccount, for an Azure cloud service, or for an Azure app service Inany of these cases, Azure CDN will copy and replicate all of the pub‐lic files present in the source system and route the users of your appautomatically to the nearest CDN node when those files are reques‐ted This offers the greatest potential performance boost whenreaching a global customer base, since communicating across conti‐nents, oceans, and satellites can cause significant latency AzureCDN can be used to host both large and small files, but it is not suit‐able for files that change content very often because as those fileschange they have to be replicated across the globe, and replicationcan be very time consuming
Message-based storage
Message-based storage systems, like Azure Queue Storage andAzure Service Bus, are designed to enable different tiers of an n-tierapplication to communicate in an occasionally connected, or asyn‐chronous, fashion This architectural pattern brings big advantages
in terms of scalability: each tier of an n-tier application can operate
at its own maximum speed, since it is not waiting on any other tier
to synchronously respond to a request Each tier communicates withthe message queue as a broker and either pushes or pulls messages
at whatever pace it can handle Another advantage of this architec‐ture is that not every tier has to be online at the same time for theapplication to operate If one or more tiers become unavailable forsome reason, either planned or not, the other tiers can still commu‐
Trang 30nicate with the message queue without interruption, and the systemwill recover when all the tiers come back online.
Queue storage Queue Storage is a simple service designed as a mes‐sage platform where messages can be placed into queues and thenread out of the queues and deleted These queues allow for messages
to be read, upon which they become invisible until the reader deletesthem If for some reason the reader of the message is unable to pro‐cess it, that message will become visible again for reprocessing Inthis way, the service offers built-in support for retries and robust‐ness
Service bus The Azure Service Bus is also a type of message queue,but it brings some more specialized features along with it Specifi‐cally, the Azure Service Bus can be used as a queue, as a messagerelay, and as a publish/subscribe message system with topics ServiceBus accounts can be created in one of two performance tiers, Basicand Standard Their features break down as illustrated in Table 1-10,you can find more details on the Azure website
Table 1-10 Service Bus performance tiers
Feature Basic tier Standard tier
Queues Yes Yes
Scheduled messages Yes Yes
Event Hubs Yes Yes
Brokered connections included 100 1,000
A brokered connection in this context is the type of connectionwhere the Service Bus is storing messages (i.e., brokering them), sothat not every endpoint in the communication path has to be con‐nected at the same time When a client connects to the service, it canreceive messages that were sent while it was offline Azure bills theseconnections based on the number of concurrent connections at peak
Trang 31time during a month The Basic tier Service Bus accounts have ahard limit of 100 concurrent connections, and the Standard tieraccounts allow 1,000 concurrent connections Extra connections arebilled on a rate schedule that you can see on the Azure portal site,but only Standard accounts can exceed the limit Service Bus utiliza‐tion, measured in millions of requests, is also billed on a rate sched‐ule.
In the message relay mode, the Service Bus can relay queue mes‐sages across the boundaries of firewalls between the cloud and anon-premise application (see Figure 1-3) It does this without punch‐ing holes in the firewall, since the relay must be opened and initiatedfrom behind the firewall This is the canonical example of a hybridapplication, partly in the cloud and partly on-premise By utilizing aService Bus relay, you can create a queue-based communicationpathway between a local app in your data center, even a legacy app,and other services in the cloud You could use a solution like this tophase your application into the cloud in stages instead of all at once
Figure 1-3 Service Bus relay facilitating queue messages across a fire‐ wall
In the topics mode, you can use the Service Bus to create topics towhich consumer services can subscribe to receive messages Eachtime you push a message into a Service Bus topic, every subscriberreceives the message as a broadcast (see Figure 1-4) This makes thecommunication one-to-many, as opposed to one-to-one
Trang 32Figure 1-4 Service Bus topics facilitating a one-to-many broadcast
NoSQL data storage
NoSQL databases, also known as Not-Only-SQL databases orNewSQL databases, are rapidly rising in popularity Instead of fea‐turing data normalization, strict transactional consistency withrecord locks, and vertical scaling through more powerful hardware,NoSQL databases embrace nonrelational data with loose schemas,multiple versions of records to avoid locking on updates, and hori‐zontal scaling through distributed server nodes This is a paradigmshift for most developers, since the traditional application develop‐ment model starts with a relational database and builds everything
on top of that foundation In today’s world, however, where scale applications require performance beyond what a traditionalrelational database can offer (even on high-end hardware), thesenew data storage solutions have risen to meet the challenge
web-Performance is not the only reason to use one of these databases,though; they also bring exciting features to developers to boost pro‐ductivity and make development more enjoyable These databasesare designed to run on schema-free data models so they can storeand retrieve data of any shape, and they are nonrelational so retriev‐ing data does not often require joins or subqueries This makesapplication changes much easier, since no migration scripts arerequired to change tables, keys, or columns and rigid object-relational mapping (ORM) tools are no longer necessary for repre‐senting data entities as objects As you update your application, youcan easily store and query entities with a new shape right alongsideolder entities that look different