Microservices with Clojure

Book description

The common patterns and practices of the microservice architecture and their application using the Clojure programming language.

About This Book

  • Relevance of the microservice architecture and benefits of Clojure's functional and simple features to implement it.
  • Learn best practices and common principles to avoid common pitfalls while developing microservices.
  • Learn how to use Pedestal to build your next microservices, secure them using JWT, and monitor them using the ELK stack

Who This Book Is For

You should have a working knowledge of programming in Clojure. However, no knowledge of RESTful architecture, microservices, or web services is expected. If you are looking to apply techniques to your own projects, taking your first steps into microservice architecture, this book is for you.

What You Will Learn

  • Explore the pros and cons of monolithic and microservice architectures
  • Use Clojure to effectively build a reallife application using Microservices
  • Gain practical knowledge of the Clojure Pedestal framework and how to use it to build Microservices
  • Explore various persistence patterns and learn how to use Apache Kafka to build event-driven microservice architectures
  • Secure your Microservices using JWT
  • Monitor Microservices at scale using the ELK stack
  • Deploy Microservices at scale using container orchestration platforms such as Kubernetes

In Detail

The microservice architecture is sweeping the world as the de facto pattern with which to design and build scalable, easy-tomaintain web applications. This book will teach you common patterns and practices, and will show you how to apply these using the Clojure programming language.

This book will teach you the fundamental concepts of architectural design and RESTful communication, and show you patterns that provide manageable code that is supportable in development and at scale in production. We will provide you with examples of how to put these concepts and patterns into practice with Clojure. This book will explain and illustrate, with practical examples, how teams of all sizes can start solving problems with microservices.

You will learn the importance of writing code that is asynchronous and non-blocking and how Pedestal helps us do this. Later, the book explains how to build Reactive microservices in Clojure that adhere to the principles underlying the Reactive Manifesto. We finish off by showing you various ways to monitor, test, and secure your microservices. By the end, you will be fully capable of setting up, modifying, and deploying a microservice with Clojure and Pedestal.

Style and approach

This book highlights the merits of the microservice architecture and its implementation with Clojure. Learn to implement microservices by migrating a monolithic application to a microservice-based architecture.

Publisher resources

Download Example Code

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  2. Monolithic Versus Microservices
    1. Dawn of application architecture
    2. Monolithic architecture
    3. Microservices
      1. Data management
    4. When to use what
    5. Monolithic applications to microservices
      1. Identifying candidates for microservices
      2. Release cycle and the deployment process
    6. Summary
  3. Microservices Architecture
    1. Domain-driven design
      1. Bounded context
      2. Identifying bounded contexts
      3. Organizing around bounded contexts
    2. Components
      1. Hexagonal architecture
    3. Messaging and contracts
      1. Direct messaging
      2. Observer model
      3. Service contracts
    4. Service discovery
      1. Service registry
      2. Service discovery patterns
    5. Data management
      1. Direct lookup
      2. Asynchronous events
      3. Combining data
      4. Transactions
    6. Automated continuous deployment
      1. CI/CD
      2. Scaling
    7. Summary
  4. Microservices for Helping Hands Application
    1. Design
      1. Users and entities
      2. User stories
      3. Domain model
    2. Monolithic architecture
      1. Application components
      2. Deployment
      3. Limitations
    3. Moving to microservices
      1. Isolating services by persistence
      2. Isolating services by business logic
      3. Messaging and events
      4. Extensibility
    4. Workflows for Helping Hands
      1. Service provider workflow
      2. Service workflow
      3. Service consumer workflow
      4. Order workflow
    5. Summary
  5. Development Environment
    1. Clojure and REPL
      1. History of Clojure
      2. REPL
    2. Clojure build tools
      1. Leiningen
      2. Boot
    3. Clojure project
      1. Configuring a project
      2. Running a project
      3. Running tests
      4. Generating reports
      5. Generating artifacts
    4. Clojure IDE
    5. Summary
  6. REST APIs for Microservices
    1. Introducing REST
    2. RESTful APIs
      1. Status codes
      2. Naming conventions
      3. Using RESTful APIs via cURL
    3. REST APIs for Helping Hands
      1. Consumer and Provider APIs
      2. Service and Order APIs
    4. Summary
  7. Introduction to Pedestal
    1. Pedestal concepts
      1. Interceptors
      2. The interceptor chain
      3. Importance of a Context Map
    2. Creating a Pedestal service
      1. Using interceptors and handlers
      2. Creating routes
      3. Declaring routers
      4. Accessing request parameters
      5. Creating interceptors
      6. Handling errors and exceptions
      7. Logging
      8. Publishing operational metrics
      9. Using chain providers
    3. Using server-sent events (SSE) 
      1. Creating interceptors for SSE
    4. Using WebSockets
      1. Using WebSocket with Pedestal and Jetty
    5. Summary
  8. Achieving Immutability with Datomic
    1. Datomic architecture
      1. Datomic versus traditional database
      2. Development model
      3. Data model
      4. Schema
    2. Using Datomic
      1. Getting started with Datomic
      2. Connecting to a database
      3. Transacting data
      4. Using Datalog to query
      5. Achieving immutability
      6. Deleting a database
    3. Summary
  9. Building Microservices for Helping Hands
    1. Implementing Hexagonal Architecture
      1. Designing the interceptor chain and context
      2. Creating a Pedestal project
      3. Defining generic interceptors
        1. Interceptor for Auth
        2. Interceptor for the data model
        3. Interceptor for events
    2. Creating a microservice for Service Consumer
      1. Adding routes
      2. Defining the Datomic schema
      3. Creating a persistence adapter
      4. Creating interceptors
      5. Testing routes
    3. Creating a microservice for Service Provider
      1. Adding routes
      2. Defining Datomic schema
      3. Creating a persistence adapter
      4. Creating interceptors
      5. Testing routes
    4. Creating a microservice for Services
      1. Adding routes
      2. Defining a Datomic schema
      3. Creating a persistence adapter
      4. Creating interceptors
      5. Testing routes
    5. Creating a microservice for Order
      1. Adding routes
      2. Defining Datomic schema
      3. Creating a persistence adapter
      4. Creating interceptors
      5. Testing routes
    6. Creating a microservice for Lookup
      1. Defining the Elasticsearch index
      2. Creating query interceptors
      3. Using geo queries
      4. Getting status with aggregation queries
    7. Creating a microservice for alerts
      1. Adding routes
      2. Creating an email interceptor using Postal
    8. Summary
  10. Configuring Microservices
    1. Configuration principles
      1. Defining configuration parameters
      2. Using configuration parameters
    2. Using Omniconf for configuration
      1. Enabling Omniconf
      2. Integrating with Helping Hands
    3. Managing application states with mount
      1. Enabling mount
      2. Integrating with Helping Hands
    4. Summary
  11. Event-Driven Patterns for Microservices
    1. Implementing event-driven patterns
      1. Event sourcing
      2. Using the CQRS pattern
    2. Introduction to Apache Kafka
      1. Design principles
      2. Getting Kafka
      3. Using Kafka as a messaging system
      4. Using Kafka as an event store
    3. Using Kafka for Helping Hands
      1. Using Kafka APIs
      2. Initializing Kafka with Mount
      3. Integrating the Alert Service with Kafka
      4. Using Avro for data transfer
    4. Summary
  12. Deploying and Monitoring Secured Microservices
    1. Enabling authentication and authorization
      1. Introducing Tokens and JWT
      2. Creating an Auth service for Helping Hands
        1. Using a Nimbus JOSE JWT library for Tokens
        2. Creating a secret key for JSON Web Encryption
        3. Creating Tokens
        4. Enabling users and roles for authorization
        5. Creating Auth APIs using Pedestal
    2. Monitoring microservices
      1. Using ELK Stack for monitoring
      2. Setting up Elasticsearch
      3. Setting up Kibana
      4. Setting up Logstash
      5. Using ELK Stack with Collectd
      6. Logging and monitoring guidelines
    3. Deploying microservices at scale
      1. Introducing Containers and Docker
        1. Setting up Docker
        2. Creating a Docker image for Helping Hands
      2. Introducing Kubernetes
      3. Getting started with Kubernetes
    4. Summary
  13. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Microservices with Clojure
  • Author(s): Anuj Kumar
  • Release date: January 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788622240