Reactive Application Development
Duncan K. DeVore, Sean Walsh, Brian Hanafee
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact
Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email:
orders@manning.com2018 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.
| Manning Publications Co.20 Baldwin RoadPO Box 761Shelter Island, NY 11964 |
Development editor: Susanna KlineReview editor: Aleksandar DragosavljeviTechnical development editor: Mark ElstonProject editor: David NovakCopyeditor: Kathy SimpsonProofreader: Alyson BrenerTechnical proofreader: William WheelerTypesetter: Marija TudorCover designer: Leslie Haimes
ISBN 9781617292460
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 EBM 23 22 21 20 19 18
Dedication
To my wife, Patty
Brian
To my family, Duncan, Jordan, Noah, Mckenna, and William
Duncan
To particularly difficult client challenges that encouraged thinking outside the box
Sean
Brief Table of Contents
Table of Contents
Foreword
In the past five years, we have seen reactive progress from a virtually unacknowledged technique used only by fringe projects within a select few corporations to part of the overall platform strategy of numerous big players in many fields, including middleware, financial services, retail, social media, and betting/gaming. Its use has moved beyond early adopters and distributed-systems experts; today, its the foundation of some of the most interesting emerging technologies, including cloud computing, microservices, streaming/fast data, and the Internet of Things.
The Reactive Manifestowhich I helped co-author in 2013defines reactive as a set of architectural design principles that are geared to meeting the demands that systems face today and tomorrow. These principles arent new but can be traced back to the 1970s and 1980s and to the groundbreaking work by Jim Gray and Pat Helland on the Tandem System and by Joe Armstrong and Robert Virding on Erlang. These pioneers were ahead of their time, however; it wasnt until the past 5 to 10 years that the technology industry at large was forced to rethink current best practices for enterprise system development and to apply the hard-won knowledge of reactive principles to todays world of distributed systems and multicore architectures.
I think that this learning experiencerunning into the limitations and constraints of traditional system design; being forced to challenge, rethink, and relearn current practices; and eventually reaping the benefits of a reactive designis probably how Duncan, Sean, and Brian would describe their journey. I met Duncan and Sean in 2012, when they were working at a startup in Philadelphia and building a product in the smart energy space, allowing customers to reduce their energy costs by interacting proactively with the electric grid. They were about a year into development of the platform, which they had built on Akka, following the principles of reactive systems, and were in the middle of building out their persistence story by using Event Sourcing and CQRS. I remember how enthusiastic they were, and their passion was contagious. Later, Sean and Duncan joined Lightbend, where theyve helped many customers around the world build highly concurrent, resilient, and elastic systems by using reactive design principles.
This book makes it clear that the authors have been there, getting their hands dirty, learning by doing. The book is packed with hard-won wisdom and practical advice that will set you on the path toward effective reactive application development. Along the way, you learn how bounded contexts, domain events, futures, actors, streaming, and Event Sourcing/CQRS compose into highly responsive, scalable, and available systems while keeping complexity under control. The book is a working book, and you have a lot of work in front of you. If you put in the hours, youll be rewarded in spades.
I hope youll enjoy the ride. I know I did.
J ONAS B ONR
F OUNDER AND CHIEF TECHNOLOGY OFFICER OF L IGHTBEND, CREATOR OF A KKA
Preface
Duncan and Sean had various Internet of Things (IoT) problems back in 2011 and realized that the typical application architectures werent going to work for them. They needed to look into other options, which led them to discovering Akka, as well as embracing concepts of domain-driven design, Command Query Responsibility Segregation (CQRS), and Event Sourcing. In embracing these concepts, they were able to concentrate on their challenging business problems and enjoyed an architecture that worked as well for 1,000 transactions a day as it did for 1 billion.
After enjoying some early successes, they quickly realized that reactive Akka applications would be the wave of the future and that scale and IoT would grow proportionately over time. Sean had already been in contact with Manning and had been working on book reviews for the company. With this relationship already in place, Duncan thought that he and Sean should write this book. Reactive architectures did become hotso much so that Duncan and Sean became very busy and stayed that way. Sean founded Reactibility and quickly took on Weight Watchers digital transformation as chief architect of the effort. Duncan, realized his dream of joining Lightbend (then named Typesafe). Finding time to write was a challenge, and they were lucky that Brian joined them to get the book finished.
The world of reactive evolved while this book was being written, but we think that the ideas are still sound; theyre being embraced by many Fortune 500 companies, including IBM, which has made a large investment in Akka technologies as well as in Lightbend. We were able to include newer subjects such as streaming and Lightbends Lagom microservice framework to keep the book fresh.
The book covers everything that a developer needs to understand to build, deploy, and test a reactive application. Akka is the backbone of the programming model, and we prefer the Scala language for its conciseness and functional beauty, but Akka works just as well with Java. In fact, most new programmers who are discovering Akka these days are using Java.
Acknowledgments
The authors gratefully acknowledge the help of technical proofreader William Wheeler and technical development editor Mark Elston, along with the staff at Manning, who did an outstanding job pushing this project to completion. Wed also like to thank the many reviewers who gave their time and expertise to make this book better: Adrian Bilauca, Amr Gawish, Arun Noronha, Christian Bach, Hugo Sereno Ferreira, Jean-Franois Morin, John Schwitz, Jrgen De Commer, Shabesh Balan, Subhasis Ghosh, Sven Loesekann, Thomas Lockney, and William E. Wheeler.