Programming Microsoft Azure Service Fabric
Second Edition
Haishi Bai
PROGRAMMING MICROSOFT AZURE SERVICE FABRIC (Second edition)
Published with the authorization of Microsoft Corporation by:
Pearson Education, Inc.
Copyright 2018 by Pearson Education, Inc.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, request forms, and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/permissions/.
No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-1-5093-0709-8
ISBN-10: 1-5093-0709-5
Library of Congress Control Number: 2018939252
1 18
TRADEMARKS
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.
WARNING AND DISCLAIMER
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The author(s), the publisher, and Microsoft Corporation shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book or from the use of the CD or programs accompanying it.
SPECIAL SALES
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact .
Editor-in-Chief: Greg Wiegand
Executive Editor: Laura Norman
Development Editor: Kate Shoup/Polymath Publishing
Managing Editor: Sandra Schroeder
Senior Project Editor: Tracey Croom/Danielle Foster
Copy Editor: Dan Foster
Indexer: Valerie Haynes Perry
Proofreader: Scout Festa
Editorial Assistant: Cindy Teeters
Cover Designer: Twist Creative, Seattle
Compositor: Danielle Foster
Graphics: Vived Graphics
To the entire Microsoft Service Fabric team, who made such a great product.
HAISHI BAI
Contents at a Glance
Contents
About the Author
HAISHI BAI, principal software engineer at Microsoft, focuses on the Microsoft Azure compute platform, including IaaS, PaaS, networking, and scalable computing services.
Ever since he wrote his first program on an Apple II when he was 12, Haishi has been a passionate programmer. He later became a professional software engineer and architect. During his 21 years of professional life, hes faced various technical challenges and a broad range of project types that have given him rich experiences in designing innovative solutions to solve difficult problems.
Haishi is the author of a few cloud computing books, and hes an active contributor to a few open-source projects. He also runs a technical blog (http://blog.haishibai.com) with millions of viewers. His twitter handle is @HaishiBai2010.
Foreword
Service Fabric can be traced back to 2001, when I was trying to solve large-scale distributed system challenges such as leader election, quorum-based replication, and perfect failure detection. As I worked on projects in 2007, such as CloudDB (which morphed into Azure DB and is powered by Service Fabric), it became clear that a generic platform would be a valuable asset for empowering developers and enterprises to implement scalable and highly available distributed systems. In 2009, I began creating such a system to support large first-party and third-party workloads. This effort led to Service Fabric, which has proven itself in production for more than a decade. Service Fabric powers critical Microsoft services such as Azure DB, Cosmos DB, Skype for Business, Microsoft Intune, Azure Resource Providers (Compute RP, Storage RP, and Network RP), Azure Software Load Balancer, Azure Network Manager, Event Hubs, Event Grid, IoT Hubs, Azure Incident Manager, Azure Monitor, Bing Cortana, and more. As of March 2018, Service Fabric runs on about 4 million cores and individually monitors and fully lifecycle-manages about 10 million microservices. Technologies like Service Fabric are treated as trade secrets by many companies and are not made available to external customers. In March 2015, Service Fabric was released to the public. By making Service Fabric publicly available (and open-sourced in March 2018), Microsoft is living by the first party == third party principle.
Service Fabric is a comprehensive platform for building Internet-scale, high-throughput, low-latency services. Besides container orchestration, it solves many fundamental distributed systems problems, such as failure detection, replicated state machines, reliable message delivery, and so on. It allows developers to naturally decompose the business application into a logical set of microservices that are individually responsible for a single business function and interact with one another over well-defined protocols for implementing business workflows. Service Fabric lets developers focus on business logic and its associated state by abstracting away machine and distributed systems details with many built-in transactionally consistent reliable data structures like dictionaries and queues that survive process crashes and machine failures. It enables programmers to think and program exactly like they do today by replacing locks with transactions. Programmers assume that the process hosting their code never crashes, and the data structures storing their state never lose or corrupt their data. With its ability to run on any OS and on any cloud, including on-premises and Edge, developers preserve their code investments across a wide variety of deployment targets. Put differently, Service Fabric allows programming large-scale applications to be just like writing simple applications.
I have known Haishi for about three years now. He has keenly followed the evolution of Service Fabric as a public service and has a deep understanding of its developer and operational aspects. He also understands intuitively how various Service Fabric layers and subsystems combine to provide the solutions to many distributed-systems problems. His first edition of this book focused on Service Fabric programming models and design patterns. This second edition is a more comprehensive follow-up companion book on Service Fabric that focuses more on the developer and operational aspects of Service Fabric and newer parts of the Service Fabric-like containers, Linux support, and more.