The increasing complexity of software systems, together with the agile way in which we develop and evolve them today, demand an approach that makes the architecture of such systems deal with change. The solution to this challenge is called modularity. Modularity is a core design principle that makes code easier to understand and maintain by splitting it into small, isolated modules. This is not a new concept, but becomes more relevant each day. A modular code base lets us change, refactor, or simply replace code of modules without breaking other parts of the system. This makes modularity the ultimate agile tool.

Bringing modularity from the design to the runtime is not always easy and straightforward and cannot be done with plain Java alone. The only mature modularity solution for Java is OSGi. Over the years, OSGi has had the reputation of being too complex and difficult to use. Recently a lot has changed in the area of tooling and frameworks, however, bringing it on par with the development experience of traditional development stacks. With this we can focus on writing code while keeping an architectural focus on modularity.

This book describes how to apply those tools and techniques available today, and gives pragmatic insights into getting up and running with the required technology in no time. Using easy to understand, concise, but real-world code samples, we explore the application of modularity toward a new breed of web applications; software as a service over the Internet, more affectionately known as cloud applications. Along the way, we address typical cloud-age topics such as RESTful Web Services, NoSQL, Provisioning, Elasticity, Auto-Scaling, Hot Updates, and Automated Failover.

Who Should Read This Book

Primarily, this book is targeted to experienced enterprise Java developers who have a keen interest in modularity and who are looking for solutions to overcome some of today’s most advanced software development problems: how to deal with change and how to manage complexity in a code base. The authors of this book use the tools and techniques described throughout the book in everyday development and have put some sophisticated cloud applications in production using them. A significant part of what you will learn here is based upon OSGi. We will focus on practical advice, rather than the more theoretical approach commonly found in other books and resources.

The book will also be useful to developers who have tried using OSGi in the past, but for some reason got stuck. Because OSGi is not a product owned by a single vendor, it is sometimes hard to find hands-on, to-the-point information on how to get things working. To those readers, this book can be an approachable and practical guide to become unstuck and get things going again. By no means is this book a complete OSGi reference, but it does contain everything that you need to know in order to build sophisticated applications in the cloud age.

How This Book Is Organized

This book is organized into three parts. Part I introduces the concepts of modularity from a high-level perspective and translates these to actual implementation details. Part II focuses on developing cloud applications and the tools and technologies required. Part III deals with deploying these applications to production and setting up advanced cloud infrastructure capabilities such as auto-scaling and failover.

Additionally, Appendix A describes an example application that puts everything from this book together in a showcase. The code of this application is hosted online, and the appendix contains instructions on how to get it.

Conventions Used in This Book

The following typographical conventions are used in this book:

Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.


This icon signifies a tip, suggestion, or general note.


This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this 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 does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Building Modular Cloud Apps with OSGi by Paul Bakker and Bert Ertman (O’Reilly). Copyright 2013 Paul Bakker and Bert Ertman, 978-1-449-34515-0.”

You can download the full source code from GitHub. For more detailed instructions on downloading the code, please see the section Finding and Running the Source Code.

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online


Safari Books Online is an on-demand digital library that delivers expert content in both book and video form from the world’s leading authors in technology and business.

Technology professionals, software developers, web designers, and business and creative professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training.

Safari Books Online offers a range of product mixes and pricing programs for organizations, government agencies, and individuals. Subscribers have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and dozens more. For more information about Safari Books Online, please visit us online.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at

Find us on Facebook:

Follow us on Twitter:

Watch us on YouTube:


A number of individuals share the credit for this book’s development and delivery. First and foremost, many thanks to O’Reilly for trusting in us and providing us the opportunity to write this book. The team provided excellent support throughout the editing, reviewing, proofreading, and publishing process.

The authors would like to express their gratitude to the many people who helped or provided support in this journey. In particular, we would like to thank Meghan Blanchette, our editor, who provided us with excellent editorial help throughout all the stages of writing, helping with interim reviews, providing feedback on content and styling, and connecting us to the rest of team at O’Reilly.

The detailed proofreading by Marcel Offermans and Arun Gupta ensured that the material was technically accurate and true to the topics of the book. Their vast experience and knowledge showed in the depth of their comments.

Finally, we would like to thank Luminis, our employer, for its encouragement and for providing us with trust and resources to combine writing this book with our daily jobs.

Get Building Modular Cloud Apps with OSGi now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.