move to azure

137
Move to Azure! FREE MICROSOFT AZURE INFORMATIONAL SESSION PAUL IRWIN, LEAD SOFTWARE ENGINEER @ FEATURE[23]

Upload: feature23-tech-strategy-software-engineering-design

Post on 14-Jan-2015

366 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Move to azure

Move to Azure!FREE MICROSOFT AZURE INFORMATIONAL SESSION

PAUL IRWIN, LEAD SOFTWARE ENGINEER @ FEATURE[23]

Page 2: Move to azure

About Me

Paul Irwin

Lead Software Engineer at feature[23]

Past experience as lead engineer on Fanatics’ ecommerce platform

Microsoft Certified Solutions Developer: Web Applications

Co-founder of Code on the Beach and Code on the Sea

[email protected]

@paulirwin

Page 3: Move to azure

Code on the Beach

The Beachside Software Engineering Conference

www.codeonthebeach.com

@CodeOnTheBeach

August 8 – 10, 2014

Registration open now at $250

Charles Petzold, Greg Young, and John Papa

World class resort hotel

Beach games and events

Excellent networking

Page 4: Move to azure

Code on the Sea

The Software Engineering Cruise

www.codeonthesea.com

@CodeOnTheSea

February 28 – March 5, 2015

Registration starting at $650

5 Day Cruise to Bahamas from Jacksonville

Carnival Fascination

Family friendly

Our greatest hospitality conference

Page 5: Move to azure

Why move to Microsoft Azure?WHAT’S IN IT FOR ME?

Page 6: Move to azure

Why move to Microsoft Azure?

Per-minute billing: pay only for what you use

Instant provisioning

Insanely scalable

Save on Windows Server, SQL Server, etc. licenses

Less infrastructure maintenance costs

No need to deal with hardware failures

Geographically-distributed High Availability / Disaster Recovery

Tons of built-in APIs and services

Page 7: Move to azure

Windows Azure Facilities

Page 8: Move to azure

Inside a Facility

Page 9: Move to azure

Inside a Container

Page 10: Move to azure

Moving to Microsoft Azure

Covered today: ASP.NET Apps (WebForms, MVC, Web API, etc.)

Not covered today: PHP, Python, Node.js, Ruby, Java, etc.

Simple apps can usually be moved as-is

Complex apps need architecture thought

Platform-as-a-Service vs Infrastructure-as-a-Service

Page 11: Move to azure

PaaS vs IaaS

Platform-as-a-Service (PaaS) Pros

Easy to scale

Can be cheaper than IaaS

Feature-rich cloud APIs

No software licenses needed

Cons

Can necessitate re-architecting

Less control

Infrastructure-as-a-Service (IaaS) Pros

Full control

Run any software unmodified

BYO or Per-minute Licenses

Cons

Usually more expensive

Must scale the “old way” or create custom scripts

You still need licenses

Page 12: Move to azure

Scenario

Employment ASP.NET MVC Web Application in Web Farm

SQL Server database

ASP.NET State Server for Session State

Facebook and Google OAuth sign-in

Lots of CSS, JS, and image content

Windows Scheduled Tasks to inform applicants of new opportunities

MSMQ queue where job applications are received for processing

Job application processor Windows Service

DR datacenter across country

Page 13: Move to azure

Step 1: Move the SQL Database

Page 14: Move to azure

Step 1: Move the SQL Database

SQL Server in an Azure Virtual Machine (IaaS solution) Pros

Ultimate power and flexibility

Full feature set

SSIS, SSAS, SSRS, SQL Agent

RDP into the VM for management

No new training required

Easy to set up AlwaysOn/mirroring HA

Option to pay per-minute with SQL Server license included

Cons EXTREMELY expensive if license included and running 24/7

Not as performant as high-end on-prem hardware

Manage updates/service packs manually

Page 15: Move to azure

Step 1: Move the SQL Database

Azure SQL Database (PaaS solution) Pros

Very affordable (starting at $5/mo)

Scales easily

Built-in High Availability

Auto-management of updates/service packs

No need for Windows Server / SQL Server licenses

Cons

Limited feature set

Limited control over instances

Page 16: Move to azure

Azure SQL Database Missing Features

• Integration Services

• Analysis Services

• Reporting Services

• SQL Agent

• SQL CLR

• Msdb, model databases

• Traditional Backup/Restore/Attach

• Distributed transactions

• Unlimited DB size

• Windows Authentication

• Extended Events

• FILESTREAM

• File Groups (i.e. ON PRIMARY)

• File management

• Full-text search

• Replication / Mirroring

• Service Broker

• XML Indexing

• “USE [database]” / Cross-DB queries

• Hekaton – In-Memory OLTP (SQL Svr 2014)

Page 17: Move to azure

Azure SQL Database Features

Just about everything else Tables, indexes, FKs, views, stored procedures, functions, triggers, CTEs,

custom types, TVPs, temp tables, logins/users, etc.

Built-in High Availability Your database synced to multiple nodes with auto failover – for FREE!

Click-to-scale

Latest T-SQL Features i.e. OFFSET/FETCH in SQL Server 2012

REST API for managing databases

CHEAP

Connect to it from elsewhere Via SSMS, SSIS, SSAS, SSRS, SQL Agent, bcp, etc.

Page 18: Move to azure

SQL Server VM IaaS Pricing

Size CPUs Memory BYO License

Web Edition

Standard Edition

Enterprise Edition

Small 1 1.75GB $66.96 $100.44 $476.16 $1,629.36

Medium 2 3.5GB $133.92 $167.40 $543.12 $1,696.32

Large 4 7GB $267.84 $301.32 $677.04 $1,830.24

X-Large 8 14GB $535.68 $602.64 $1,354.08 $3,660.48

A5 (HM) 2 14GB $297.60 $331.08 $706.80 $1,860.00

A6 (HM) 4 28GB $595.20 $628.68 $1,004.40 $2,157.60

A7 (HM) 8 56GB $1,190.40 $1,257.36 $2,008.80 $4,315.20

Page 19: Move to azure

Azure SQL Database PaaS Pricing

Database Size Monthly Price

20 MB FREE

100 MB $5.00

1 GB $9.99

5 GB $25.98

10 GB $45.96

50 GB $125.88

100 GB $175.83

150 GB $225.78

> 150 GB * Premium Instance Pricing *

Page 20: Move to azure

The Amazing NEW Button

Page 21: Move to azure

Creating a New Azure SQL DB

Page 22: Move to azure

Subscriptions and Directories

Highest level: Directories Equivalent to Active Directory directories

One is created for you automatically

Can contain multiple Subscriptions

Should be organization-level

Next level: Subscriptions Now must belong to a Directory

Contain multiple Services

Tied to a credit card

Should be used for keeping billing separate

Lowest level: Services Must belong to a Subscription

Changing the Subscription later is not fun

Page 23: Move to azure

SQL Azure Firewall Rules

Page 24: Move to azure

Move Your Data/Schema to SQL Azure

1. Entity Framework Migrations

2. “Generate Scripts” from SSMS

3. BCP.exe

4. BACPAC to Blob Storage

5. RedGate SQL Compare and SQL Data Compare

Page 25: Move to azure

Entity Framework Migrations

Schema and seeded data only

Update-Database -ConnectionStringName ProdForMigrations

Database.SetInitializer(new MigrateDatabaseToLatestVersion(…))

Page 26: Move to azure

“Generate Scripts” for SQL Azure

Page 27: Move to azure

BCP.exe to SQL Azure

bcp AdventureWorks2012.Sales.Customer in C:\Users\user\Documents\MoveDataToSQLAzure.txt -c -U username@servername -S tcp:servername.database.windows.net -P password

http://tinyurl.com/azuresqlbcp

Page 28: Move to azure

BACPAC to Blob Storage

In SSMS: Tasks / Export Data-tier Application / Save to Windows Azure

Save to Blob Storage

Will throw errors on any Azure-incompatible objects

Load BACPAC from Blob Storage into NEW database

http://tinyurl.com/azuresqlbacpac

Page 29: Move to azure

RedGate Tools

SQL Compare to compare schema

SQL Data Compare to compare table records

Beware of long-connection timeouts!

$495 from www.redgate.com

Page 30: Move to azure

Step 2: Move the ASP.NET App

Page 31: Move to azure

Options for Web Hosting in Azure

Azure Web Sites

• PaaS• Cheaper to get started• Supports ASP.NET,

Node.js, PHP, etc.• Simpler to deploy• Less powerful

Azure Cloud Services

• PaaS• Cheaper to scale• Only ASP.NET• Staging/Production VIP

Swap Deployments• Very powerful• RDP into instance(s)• Auto-updated

IIS in a Windows

Server VM• IaaS• Expensive• Full IIS/Windows

Features• Need to manage

Windows Updates, etc.

Page 32: Move to azure

Azure Cloud Service Web Roles

ASP.NET WebForms, MVC, Web API, WCF, etc.

Provisions a Windows Server VM and deploys your app to IIS

Control over version of Windows Server (IIS) Windows Server 2008 R2, 2012, or 2012 R2

No need to pay for Windows Server license

Staging/Production deployments with VIP Swap

Temporary or persisted local storage

Load balancing built-in

Click-to-scale or Auto-scale

HTTP, HTTPS, or TCP internal/external endpoints

Page 33: Move to azure

Azure Cloud Service Pricing

Size Name Virtual Cores Memory Price Per Hour Price Per Month

Extra-Small Shared 768 MB $0.02 ~ $15

Small 1 1.75 GB $0.08 ~ $60

Medium 2 3.5 GB $0.16 ~ $120

Large 4 7 GB $0.32 ~ $239

Extra-Large 8 14 GB $0.64 ~ $477

High-Memory A5 2 14 GB $0.35 ~ $261

High-Memory A6 4 28 GB $0.71 ~ $529

High-Memory A7 8 56 GB $1.41 ~ $1,050

www.windowsazure.com/en-us/pricing/details/cloud-services/

Page 34: Move to azure

Cloud Service Deployment

1. Create an Azure Cloud Service project in your VS sln

2. Add your ASP.NET web site to the Cloud Service project as a Web Role

3. Package your Cloud Service

4. Upload package to Azure, provisions new Staging environment

5. Test staging site at unique URL

6. VIP Swap staging into production (and vice versa)

7. Test production

8. Stop staging environment (save on billing costs)

Page 35: Move to azure

Creating a Cloud Service

Page 36: Move to azure

Our Existing Application

Page 37: Move to azure

Creating a Cloud Service Project

Page 38: Move to azure

Add Existing Project as Web Role

Page 39: Move to azure

Choose Web Project as Web Role

Page 40: Move to azure

Set Scale

Page 41: Move to azure

Package Cloud Service for Deployment

Page 42: Move to azure

Deployment Options

Page 43: Move to azure

Upload to Azure Portal

Page 44: Move to azure

Uploading a Package

Page 45: Move to azure

Provisioning Staging Environment

Page 46: Move to azure

Up and Running

Page 47: Move to azure

Finding Staging Site URL

Page 48: Move to azure

Testing Staging

Page 49: Move to azure

VIP Swap into Production

Page 50: Move to azure

Test Production

Page 51: Move to azure

DNS Setup

Cloud Services CNAME only

i.e.: www.myapp.com is CNAME’d to myapp.cloudapp.net

Redirect from myapp.com to www.myapp.com

Web Sites CNAME or A

Must verify domain name with awverify CNAME

Can be finicky!

Page 52: Move to azure

Delete Staging Environment

Page 53: Move to azure

Monitoring your Cloud Service

Page 54: Move to azure

Scaling your Cloud Service

Page 55: Move to azure

Step 3: Handling Session State

Page 56: Move to azure

Azure Session State Options

Table Storage

•Cheap•Slower•Scalable•HA built-in•Persisted

SQL Database

•Cheap-ish•Fast-ish•Not as scalable•HA built-in•Persisted

Cache Role

•Costly•Fast•Scalable•HA available•Feature rich•Not persisted

In-Role Cache

•No cost•Fast•Scalable•HA with scale•Feature rich•Not persisted

Page 57: Move to azure

Enable In-Role Caching

Page 58: Move to azure

Enable Cache Providers

Page 59: Move to azure

Set Cache Client Settings

Page 60: Move to azure

Step 4: Enabling ACS for OAuth

Page 61: Move to azure

Azure Access Control Service

Provides managed identity federation

Supports Active Directory and OAuth

FREE! Like really, truly FREE!

OAuth Providers: Microsoft Account

Google

Yahoo!

Facebook

Uses Windows Identity Foundation

More info: http://msdn.microsoft.com/library/azure/hh147631.aspx

Page 62: Move to azure

Overview

Page 63: Move to azure

Create an ACS Namespace

Page 64: Move to azure

Manage ACS Namespace

Page 65: Move to azure

ACS Management Portal

Page 66: Move to azure

Add Identity Provider(s)

Page 67: Move to azure

Add Facebook Application

Page 68: Move to azure

Configured Identity Providers

Page 69: Move to azure

Add Relying Party Application

Page 70: Move to azure

Generate Default Rules

Page 71: Move to azure

Configure WIF

Page 72: Move to azure

Web.config Changes

Page 73: Move to azure

More Web.config Changes

Page 74: Move to azure

[Authorize] Actions

Page 75: Move to azure

Secure Page Redirect

Page 76: Move to azure

Sign In at Identity Provider

Page 77: Move to azure

… and we’re authenticated!

Page 79: Move to azure

Step 5: Store the Images

Page 80: Move to azure

Azure Storage Options

Blob•Any binary data•Cheap•Scalable•HA built-in

Table•Structured non-relational data•Cheap•Scalable•HA built-in

Queue•FIFO messages•Cheap•Scalable•HA built-in

SQL•Structured relational data•Pricey•Somewhat scalable•HA built-in

Page 81: Move to azure

Blob Storage Overview

Any binary data: images, files, disks, backups, etc.

Block blobs: read/write entire blob at once

Page blobs: read/write pages of blob randomly

LRS: Locally-redundant Storage – 3 copies in same facility

GRS: Geographically-redundant Storage – 6 copies in 2 regions

LRS Pricing: 5 to 6.8 cents per GB per month or less

GRS Pricing: 8.5 to 9.5 cents per GB per month or less

New ZRS (Zone-redundant Storage) to match Amazon

Page 82: Move to azure

Blob Storage Developer Workflow

1. Connection string: UseDevelopmentStorage=true

2. Start debugging, starts storage emulator

3. Test app

4. When ready to deploy, transform connection string

Page 83: Move to azure

Setting up Blob Storage

Page 84: Move to azure

Storage Dashboard

Page 85: Move to azure

Manage Access Keys

Page 86: Move to azure

Setup Connection Strings

Page 87: Move to azure

Create a Blob

Page 88: Move to azure

List Blobs

Page 89: Move to azure

Get Blob Data

Page 90: Move to azure

Step 6: Azure CDN for static content

Page 91: Move to azure

When to use the Azure CDN

Content Delivery Networks efficiently cache static content at edge nodes close to your site viewers

Great for JavaScript, CSS, images, etc.

Well suited for content that doesn’t change often

Helps your app scale

Frees up your web server to do other things

Page 92: Move to azure

Azure CDN Requirements

Blob Storage CDN Blob container must be publicly available

Blob container must allow anonymous access

Items should be less than 10 GB in size

Cloud Service CDN Content must be under /cdn folder

Cloud Service must be a Production deployment

Content must be available on port 80

Content should be static

Page 93: Move to azure

Azure CDN Pricing

1 cent per month for every 100k transactions

12 cents per GB transferred per month For North America and Europe; other zones more expensive

Price drops per GB after 10 TB transferred per month

Page 94: Move to azure

Create New CDN Endpoint

Page 95: Move to azure

CDN Endpoint Details

Page 96: Move to azure

Replace Content URLs

Blob storage URL: http://f23azuredemo.blob.core.windows.net/images/Microsoft.png

Equivalent CDN URL: http://az590111.vo.msecnd.net/images/Microsoft.png

Alternatively, create a CNAME DNS entry for your CDN hostname

Page 97: Move to azure

Step 7: Scheduled Tasks

Page 98: Move to azure

Azure Scheduler

Allows you to schedule HTTP requests to invoke your code Or post a message to a storage Queue

Scheduled tasks are “jobs”

Jobs are organized into Job Collections

Page 99: Move to azure

Azure Scheduler Pricing

Free Tier FREE

1 job collection

Up to 5 jobs

Max hourly frequency

Up to 3,600 executions per month

Standard Tier $10/mo

Up to 10 job collections

Up to 50 jobs per collection

Max every minute frequency

Unlimited executions per month

Page 100: Move to azure

Creating a Job Collection

Page 101: Move to azure

Creating a Job Collection

Page 102: Move to azure

Create New HTTP Job

Page 103: Move to azure

Create New Queue Job

Page 104: Move to azure

Define a Schedule

Page 105: Move to azure

Step 8: Move the MSMQ Queue

Page 106: Move to azure

Scenario

MSMQ queue

Each message is a job application

Service picks up job applications for processing

User

Job Application

MSMQ

Processing Servi

ce

Page 107: Move to azure

Azure Queue Offerings

Azure Storage Queue 0.5 cents per 100k transactions

7 cents per GB (LRS)

Simple REST API

Max 64KB message size

Leasing to handle service failures

Transaction logging

7-day limit

Batched receive only

Azure Service Bus 1 cent per 10k messages

WCF Integration

Duplicate detection

Transaction support

Can exceed 7 days

Messages should be < 64KB

256 KB message size limit

Guaranteed FIFO

Batched send & receive

Page 108: Move to azure

Azure Storage Queue Workflow

Posting Messages

1. Create Queue Client

2. Create new CloudQueueMessage

3. Call AddMessageAsync

Receiving Messages

1. Create Queue Client

2. Call GetMessageAsync

3. If null, return or wait to try again

4. Process message however you like

5. Call DeleteMessageAsync

Page 109: Move to azure

Add Message to Storage Queue

Page 110: Move to azure

Get Message from Queue

Page 111: Move to azure

Azure Service Bus Workflow

Prerequisite: Create SB namespace and queue, get credentials

Posting Messages

1. Create Service Bus QueueClient

2. Create new BrokeredMessage

3. Call SendAsync

Receiving Messages

1. Create Service Bus QueueClient

2. Call ReceiveAsync

3. If null, return or wait to try again

4. Process message however you would like

5. Call CompleteAsync on success, or Abandon on failure

Page 112: Move to azure

Creating a Service Bus Queue

Page 113: Move to azure

Creating a Service Bus Queue

Page 114: Move to azure

Configure Service Bus Queue

Page 115: Move to azure

Add Message to SB Queue

Page 116: Move to azure

Receive Message from SB Queue

Page 117: Move to azure

Step 9: Application Processing Service

Page 118: Move to azure

Scenario

Job Application Processing Service

Windows Service

Takes applications from MSMQ – now Service Bus or Storage Queue

Sends emails to employers, stores data in SQL

Page 119: Move to azure

Azure Worker Roles

Similar to Cloud Service Web Roles Same instance sizing and pricing

Same scaling options

Same deployment model

Same benefits/tradeoffs

Designed for: WCF services

WF services

while (true) { … }

Page 120: Move to azure

Add New Worker Role Project

Page 121: Move to azure

Create New Worker Role Project

Page 122: Move to azure

Project Structure

Page 123: Move to azure

Worker Role Lifecycle

bool OnStart() Called when role is started

Load initial state, set options

void Run() This is where your main work happens

while (true) { … }

void OnStop() Called when role is stopping

This can be a manual stop or Windows Updates

Clean up after your service

Max 5 minutes, then terminated

Page 124: Move to azure

Worker Role RunAsync

Page 125: Move to azure

Process Queue Messages

Page 126: Move to azure

Step 10: High Availability and Disaster Recovery

Page 127: Move to azure

HA and DR: SQL Database

HA Built-in 3 nodes in same facility

One Primary and Two Secondary nodes

Transient failure retry logic required

DR options BACPAC to another data center

Sync data with SSIS (from another server/VM)

RedGate Cloud Services – cloudservices.redgate.com

Backup SQL Database to Blob Storage or Amazon S3

Transactionally-consistent

Set custom retention policy

Page 128: Move to azure

RedGate Cloud Services Pricing

Backup Frequency Monthly Price

Weekly $2.50

Daily $10.00

2x Daily (12 hrs) $20.00

4x Daily (6 hrs) $40.00

Does not include storage, transaction, or bandwidth costs.

Page 129: Move to azure

DON’T HAVE A BACKUP STRATEGY!

Page 130: Move to azure

HA and DR: Azure Storage

HA Built-in LRS: 3 copies of data in same facility

ZRS: 3 copies of data in different facilities, same region

GRS: 6 copies of data, 3 each in 2 regions

DR Options Rely on ZRS or GRS

RedGate Cloud Services – cloudservices.redgate.com

Backup blobs or tables to another blob storage region or Amazon S3

Table backups are compressed JSON

Same pricing as SQL backup

Page 131: Move to azure

HA and DR: Cloud Services

HA Available Should use at least 2 instances of each web/worker role

99.95% SLA if at least 2 instances

Update domains maintain uptime

DR Options Azure Traffic Manager

Cloud service running in multiple regions

Failover to other region, or load balance (costly)

BYO Traffic Manager

F5, Juniper, etc.

Page 132: Move to azure

HA and DR: Service Bus Queues

HA Built-in 99.9% monthly SLA

DR Options Persist queue messages elsewhere as backup (blob, table, sql, etc)

Multiple SB namespaces/queues in different regions

Sync queues

Restore queue messages from backup in other region (if needed)

Page 133: Move to azure

Summary

Page 134: Move to azure

Summary

The Old Way ASP.NET Web Application

SQL Server Database

ASP.NET State Server

Manual OAuth Wire-up

CSS, JS, Image content in IIS

Windows Scheduled Tasks

MSMQ queue for job applications

Windows service

DR datacenter across country

The Azure Way Cloud Service Web Role

Azure SQL Database

In-Role Distributed Caching

Azure Access Control Service

Azure CDN, Blob Storage

Azure Scheduler

Azure Storage Queue / Service Bus

Cloud Service Worker Role

HA by default, easy DR options

Page 135: Move to azure

Code Changes

Use only SQL Database features available

Add transient failure retry logic for ADO.NET queries

Add HrdClient for Azure Access Control Service

Rewrite URLs for Azure CDN

Code to read/write images from Blob Storage

Code to handle HTTP or queue message from scheduled task

Handle Storage Queue or Service Bus Queue messages

Move Windows Service code to Worker Role

Page 136: Move to azure

Azure Features Not Covered

Table Storage

Web Sites

Virtual Machines

Mobile Services

Mobile Push Notifications

HDInsight – Hadoop on Azure

Media Services – Olympics

Service Bus Topics

Service Bus Relays

Service Bus Notification Hubs

Cache Roles

BizTalk Services

Recovery Services

Virtual Networks

Management Alerts

Azure Active Directory

Multi-factor Authentication

Rights management

Add-ons

… and other features added since I made this presentation

Page 137: Move to azure

Q&A