Online Store Application using Microservices and Bluemix

Share this post:

Applications are changing. Users are expecting a more interactive experience on a wide variety of devices. Applications need to be able to scale, be highly available and be able to roll out continuous updates to quickly react to browser, mobile device, API, and security changes. Creating one large monolithic application may no longer make sense for several reasons:

  • Large applications can be overwhelming and slow for your team to develop, test, and deploy
  • Large applications may force you to commit to a technology stack and make it very difficult to adapt
  • Scaling large applications mean creating multiple instances of the entire environment instead of scaling a small piece.

The Microservices architectural pattern is a great solution for these problems.

The concept is simple—break your application into multiple independent applications, each with a clear purpose. The applications talk to each other using HTTP over REST or a message queue. Each of these applications can be written in whatever language is best for its job. Developers and IDEs are happy because they are working with a smaller code base and they have more flexibility to make changes to their more manageable application. Each application can be monitored, scaled or updated independently to match demands.

Simple microservices online e-commerce sample

In this blog, Ram Vennam and I provide a very simple microservices online e-commerce sample, defined by three separate applications. One of the major strengths of microservices is the ability to choose which language/runtime you want to use for each application.

For this sample we decided to use Node.js for our Catalog backened due to it’s non-blocking, event-driven I/O, it’s ability to handle many requests, and for the use of a non-relational database for our catalog of items. For the orders we decided on Java Jax-RS for its ability to handle and process many orders on our store and take advantage of a relational SQL database. PHP was chosen for the UI due to it being super easy to create a UI.

The three sections below will show you the steps to copy and run these applications in your own Bluemix environment.

What you will need

Applications Overview

Application 1: Catalog API – A backed RESTful API to keep track of all the items in the store. We will use Node.js with Express framework. The catalog of items will be persisted in a Cloudant database.

Application 2: Orders API – Another backend RESTful API to keep track of all store orders. We will implement this using Java JAX-RS and use JPA to store the orders in a SQL Database.

Application 3: UI – A simple UI that displays all the items in the store catalog, and can create orders. This UI will call both REST APIs provided by the applications above. We will use PHP to write this part.

Each of these applications can use whatever Bluemix services they need. For example, if my catalog application gets high demand unpredictably, we can simply attach the AutoScaling service to it, and not worry about it.

Application 1 – Catalog API

Follow the steps below to deploy your Node.js API back-end.

  1. Sign up or log into Bluemix
  2. Click Deploy to Bluemix button below:
    Bluemix button

  3. All fields on the next page will be pre-filled for you. Select Deploy.
  4. Node.js Catalog Deploy

  5. Once the application is done deploying to Bluemix, select View your App (keep your app open as you will need the route for application 3, not the git url)
  6. Node.js Catalog View

  7. To see the items in your catalog follow the instructions on the homepage. Note that the format will be in JSON. We will make a UI application later, which can display these items in a more user-friendly way.

    Node.js JSON

Congratulations! You just setup your Node.js back-end store API!

Application 2 – Orders API

Follow the steps below to create the Java Orders back-end. Due to the nature of this application handling customer orders and potential billing information, failures are not acceptable for this service and security is our utmost importance. We have selected to use Java EE because this application needs a technology stack that is robust, well supported, standards driven, and can provide transactional support. The WebSphere Application Server Liberty buildpack on Bluemix offers us an enterprise-grade Java EE application server while still being extremely light weight and dynamic. The jax-rs feature is provided by default and allows us to quickly create RESTful end points with simple annotations.

  1. Click Deploy to Bluemix button below:
    Bluemix button

  2. All fields on the next page will be pre filled for you. Select Deploy.
    Java Orders Deploy
  3. Once the application is done deploying to Bluemix, select View your App (keep this tab open as you will need the route for application 3, not the git URL).
    Java Orders View App

Application 3 – UI

Follow the steps below to create a PHP front-end for your Node.js and Java back-end.

  1. This application requires 2 user-provided services. One for you Catalog API and one for your Orders API. Start by opening a terminal and type: cf login.
  2. Enter your Email and password. These are associated with your Bluemix Account.
  3. Next, paste this command in your terminal to create our first user-provided service for the Catalog API: cf cups catalogAPI -p "host" and hit enter. This will prompt you for the host. This is the URL for your Catalog API application we just deployed. For example,
  4. We are going to do the same as the step above, but for our Orders API. Go ahead and paste this command into your terminal cf cups ordersAPI -p "host" and hit enter. When it prompts you for the host, enter the URL for your Orders API application. For example,
  5. Now that we have our services created, it’s time to Deploy to Bluemix by selecting the button below:
    Bluemix button

  6. Once your application has finished deploying, click the View Your App button to see your PHP UI communicating with your Node.js Catalog API and your Java Orders API!

Congrats! You now have a full microservices sample consisting of a Node.js Catalog back-end, a Java Orders back-end, and a PHP UI.

—Andrew Lohr, Ram Vennam


More stories
May 1, 2019

Two Tutorials: Plan, Create, and Update Deployment Environments with Terraform

Multiple environments are pretty common in a project when building a solution. They support the different phases of the development cycle and the slight differences between the environments, like capacity, networking, credentials, and log verbosity. These two tutorials will show you how to manage the environments with Terraform.

Continue reading

April 29, 2019

Transforming Customer Experiences with AI Services (Part 1)

This is an experience from a recent customer engagement on transcribing customer conversations using IBM Watson AI services.

Continue reading

April 26, 2019

Analyze Logs and Monitor the Health of a Kubernetes Application with LogDNA and Sysdig

This post is an excerpt from a tutorial that shows how the IBM Log Analysis with LogDNA service can be used to configure and access logs of a Kubernetes application that is deployed on IBM Cloud.

Continue reading