Spring 5.0 Microservices Second Edition Build scalable microservices with Reactive Streams, Spring Boot, Docker, and Mesos This book is based on Spring Version 5.0 RC1 Rajesh R V BIRMINGHAM - MUMBAI Spring 5.0 Microservices Second Edition Copyright © 2017 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: June 2016 Second edition: July 2017 Production reference: 1120717 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78712-768-5 www.packtpub.com Credits Author Copy Editor Rajesh R V Zainab Bootwala Reviewer Project Coordinator Aditya Abhay Halabe Prajakta Naik Commissioning Editor Proofreader Aaron Lazar Safis Editing Acquisition Editor Indexer Chaitanya Nair Aishwarya Gangawane Content Development Editor Graphics Siddhi Chavan Abhinash Sahu Technical Editor Production Coordinator Abhishek Sharma Shraddha Falebhai About the Author Rajesh R V is a seasoned IT architect with extensive experience in diversified technologies and more than 18 years of airline IT experience. He received a degree in computer engineering from the University of Cochin, India, and he joined the JEE community during the early days of EJB. During his course as an architect, he worked on many large-scale, mission-critical projects, including the new generation Passenger Reservation System (iFly Res) and next generation Cargo Reservation System (Skychain, CROAMIS) in the Airline domain. At present, as a chief architect at Emirates, Rajesh handles the solution architecture portfolio spread across various capabilities, such as JEE, SOA, NoSQL, IoT, cognitive computing, mobile, UI, and integration. At Emirates, the Open Travel Platform (OTP) architected by him earned the group the prestigious 2011 Red Hat Innovation Award in the Carved Out Costs category. In 2011, he introduced the innovative concept of the Honeycomb architecture based on the hexagonal architecture pattern for transforming the legacy mainframe system. Rajesh has a deep passion for technology and architecture. He also holds several certifications, such as BEA Certified Weblogic Administrator, Sun Certified Java Enterprise Architect, Open Group Certified TOGAF practitioner, Licensed ZapThink Architect in SOA, and IASA global CITA-A Certified Architecture Specialist. He has written Spring Microservices and reviewed Service-Oriented Java Business Integration by Packt Publishing. Acknowledgments I would like to thank everyone at Packt who I've worked closely with to make my dream come true. Thanks to the reviewers; their in-depth reviews helped improve the quality of this book. This book would have never been possible without the encouragement from my excellent colleagues at Emirates with whom I worked with and learned from. A very special thanks goes to Neetan Chopra, Senior Vice President, and Thomas Benjamin, CTO, GE Aviation, for their constant support and help. Special thanks to Daniel Oor and Tomcy John for their help. A heartfelt thanks goes to my wife, Saritha, for her tireless and unconditional support that helped me focus on this book. Thanks to my kids, Nikhil and Aditya. I have taken away a lot of the time that I'd spend playing with them to write this book. A huge thanks goes to my father, Ramachandran Nair, and my mother, Vasanthakumari, for their selfless support that helped me reach where I am today. About the Reviewer Aditya Abhay Halabe is a full-stack web application developer at Springer Nature's technology division. His primary technology stack includes Scala, Java, micro-web services, NOSQL databases, and multiple frameworks such as Spring, Play, and Angular. He has a very good understanding of Agile development, with continuous integration, which includes knowledge of DevOps, Docker, and automated deployment pipelines. He is passionate about his work and likes to take on new challenges and responsibilities. Previously, Aditya has worked as a consultant with Oracle, and as a software developer with John Deere. www.PacktPub.com For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. https://www.packtpub.com/mapt Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career. Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Customer Feedback Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1787127680. If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products! Table of Contents Preface 1 Chapter 1: Demystifying Microservices 8 Evolution of microservices 8 Business demand as a catalyst for microservices evolution 9 Technology as a catalyst for microservices evolution 12 Imperative architecture evolution 12 What are Microservices? 13 Microservices - The honeycomb analogy 17 Principles of microservices 17 Single responsibility per service 18 Microservices are autonomous 18 Characteristics of microservices 19 Services are first class citizens 19 Characteristics of service in a microservice 20 Microservices are lightweight 21 Microservices with polyglot architecture 22 Automation in microservices environment 23 Microservices with a supporting ecosystem 24 Microservices are distributed and dynamic 24 Antifragility, fail fast, and self healing 26 Microservices examples 27 An example of a holiday portal 27 An example of a travel agent portal 30 Microservices benefits 32 Supports polyglot architecture 32 Enables experimentation and innovation 33 Elastically and selectively scalable 34 Allows substitution 36 Enables to build organic systems 37 Helps managing technology debt 38 Allowing co-existence of different versions 39 Supporting building self-organizing systems 40 Supporting event-driven architecture 41 Enables DevOps 42