Moving from BigCommerce to Microservices-Based E-Commerce
Tags: microservices, webdev
Published: 2021-06-25 01:53:34

BigCommerce includes many features and services, but if you want to take every opportunity to engage with your customers, you need a solution of which you’re in complete control.

There’s no better way to do that than replacing it with microservices. After all, this is [the approach Amazon took](https://resources.fabric.inc/blog/answers/amazon-ecommerce-platform) to scale and become so successful. You can move one step at a time, adding reusable core components that act as a foundation for multiple frontend sales channels.

In this post, we’ll discuss replacing BigCommerce with a microservices-based alternative, looking at the reasons for making the change. Then we'll discuss the specifics, along with a few examples of what to do code-wise. 

**Note:** We've written before about migrating away from [classic e-commerce monoliths](https://resources.fabric.inc/blog/answers/enterprise-ecommerce-platforms) like [Salesforce Demandware](https://resources.fabric.inc/blog/salesforce-commerce-to-microservices). As you'll see, many of the same concepts and migration practices apply to modern monoliths like Shopify Plus.


## Why Microservices?

Microservices have several advantages over a pre-built, one-size-fits-all solution. 

### Security

- Microservices are modular and interchangeable by design. That means your developers can work on them without affecting other parts of your system. It also means you can quickly make and test changes and slot in older or alternate versions of your code. 

- Being able to respond fast and hone in on potential problem areas are key advantages of microservices. By contrast, a large platform may take time to fix holes, and the process of upgrading might be out of your control. 

### Flexibility

- BigCommerce offers you several templates and has plenty of features, but you are also at the mercy of any changes it makes. 

- With your own microservices, you can update them when you like. You can choose the fields and data format to work with and decide how your services connect and share information. 

- You can make every decision related to your business yourself. That may seem daunting, but specialists can help, even if you’re using your own solution.

### Costs
- While BigCommerce is extendable, many of the upgrades aren’t cheap. Even one can significantly add to your costs, and the more you have, the bigger the hit.

- [Estimates suggest](https://thenewstack.io/microservices-pricing-whats-it-all-going-to-cost/) ongoing costs for microservices can drop by up to 90%, and that’s before you factor in the productivity gains for your developers.


## Replacing BigCommerce

BigCommerce’s headless architecture is ideal when shifting to microservices as you can pick and choose what you replace relatively quickly. Furthermore, by taking a modular approach and focusing on one service at a time, you can gradually transition. 

Moving one service at a time makes it easy to identify any issues and roll back any mistakes. If you have trouble with any of your new services, just swap the old one back in, then test and improve the new one until it does what you expect.

### Step 1: Decide where to start with the migration

There isn’t a fixed approach to migrating from one platform to another, and you might take several valid routes. Let’s look at some of BigCommerce’s services and decide what to implement using microservices.

#### Product information management (PIM)

Product Information Management is one of the most important tasks in e-commerce, and being able to update and access this data is crucial. BigCommerce has [several apps available](https://www.bigcommerce.com/apps/product-information-management-pim/) to help with it.

With microservices, though, you can customize everything from storing the data you need in the format of your choice to making it available to every channel you use. So you aren’t limited to finding the closest fit from a range of options.

fabric’s [PIM system](https://resources.fabric.inc/blog/pim-software) gives you a ready-made solution, allowing you to make changes using an intuitive UI and supporting features like multiple product hierarchies, auditing, and one-click migration.

#### Order management system (OMS)

Your order management system needs to handle payments, store the user’s order, and make sure it gets dealt with. In addition, logistical issues, like stock management, need it to run flawlessly.

BigCommerce has its own OMS with a [defined workflow](https://support.bigcommerce.com/s/article/Order-Management-in-BigCommerce) and several extensions available in its marketplace.

Your own OMS will be a crucial component of your business. It will take time to build and to get everything right. But a customized system built to your specifications can make the rest of your business run smoothly and efficiently.

fabric [has its own OMS](https://fabric.inc/oms), and using this as a starting point for your system can save you a lot of time and ensure you nail the basics.

#### Other supporting services

PIM and OMS are essential to nearly all e-commerce businesses. The other services you pick will depend on which of BigCommerce’s capabilities you currently use and want to improve or replace. 

BigCommerce [offers many features](https://www.websitebuilderexpert.com/ecommerce-website-builders/comparisons/bigcommerce-vs-shopify/) out of the box. You might want to replicate its customer review system or perhaps control user access for your staff.

If you want to take things slowly, starting with a small, non-essential service can be a great way to get going.

### Step 2: Build a middle layer

As you switch from BigCommerce to your new microservices, you need to make sure the system sends requests to the right place. You can do this with an API Gateway. [Setting one up](https://medium.com/bigcommerce-developer-blog/how-i-built-a-serverless-bigcommerce-app-on-aws-4efe21446bea) lets you choose which services deal with requests, so you can pick and choose what your new services handle.

![ECommerce microservice architecture diagram, showing services surrounding central service mesh](https://i.imgur.com/qdI26Z3.png)

#### Swap out legacy services

Once the middle layer is in place, you can retire old services and add your new ones. You can also swap things back and forth between new and existing services for testing or even filter requests so that some are dealt with by BigCommerce, and some go to your new setup.

### Step 3: Migrate data from BigCommerce to microservices

When switching over, you’ll need to get your data out of BigCommerce and into your new backend database. It’s easy to export data from BigCommerce: you can [generate a CSV](https://support.bigcommerce.com/s/article/Importing-Exporting-Products) file that contains everything, or you can pick and choose the fields to export.

As well as getting the fields out, you need to decide on your new data structure. Will you use identical field names for the fields you want, or will you change them? You may want to allow for additional fields too.

If you want to extract data from BigCommerce dynamically, you can do that [via its APIs](https://developer.bigcommerce.com/api-reference). The latest version of its REST API is three, faster and more efficient, though it doesn’t yet include everything in the older version two. 

There’s also a GraphQL API, though this is [still in early access](https://developer.bigcommerce.com/api-docs/storefront/graphql/graphql-storefront-api-samples) and feature-incomplete. Being able to build your own full-featured API in any language is one advantage of microservices.

Let’s look at the data format for [shopping cart items](https://developer.bigcommerce.com/api-reference/storefront/carts/cart-items/addcartlineitem):

| ** Field Name  ** | ** Data Type ** |
| --- | --- |
| id | string |
| customerId | integer |
| email | string |
| currency | object |
| isTaxIncluded | boolean |
| baseAmount | number |
| discountAmount | number |
| cartAmount | number |
| coupons | array[object] |
| discounts | array[object] |
| lineItems | object |
| createdTime | string |
| updatedTime | string |
| locale | string |

Here’s the JavaScript for adding this code to a message queue, adapted from the [AWS documentation](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/sqs-examples-send-receive-messages.html). You can also find code there to receive the data, which doesn’t need much adaptation.

I’ve picked out a few attributes from the list above. You can add more, using the same format, or remove any you don’t want.

``` javascript

// Imports for AWS
const { SQSClient, SendMessageCommand } = require("@aws-sdk/client-sqs");

// Set this to your region
const REGION = "us-east-1"; 

// The parameters, swap in what you need, and out what you don’t
const params = {
  DelaySeconds: 10,
  MessageAttributes: {
    id: {
      DataType: "String",
      StringValue: "475",
    },
    customerId: {
      DataType: "String",
      StringValue: "562567",
    },
    baseAmount: {
      DataType: "Number",
      StringValue: "79.99",
    },
discountAmount: {
      DataType: "Number",
      StringValue: "59.99",
    },
  },
  MessageBody:
    "Shopping cart information.",
  QueueUrl: "SQS_QUEUE_URL", // Your queue URL, e.g. 'https://sqs.REGION.amazonaws.com/ACCOUNT-ID/QUEUE-NAME'
};

const sqs = new SQSClient({ region: REGION });

const run = async () => {
  try {
    const data = await sqs.send(new SendMessageCommand(params));
    console.log("Success, message sent. MessageID:", data.MessageId);
  } catch (err) {
    console.log("Error", err);
  }
};
run();
```

### Step 4: Test and repeat

As you replace each service, you should test thoroughly, making sure everything works correctly. That makes it easier to fix issues, as you can be reasonably sure that they relate to your recent changes. 

Once everything is working, move onto the next service and repeat the process. This iterative, step-by-step approach lets you stay focused and get the right balance between working on new services and putting them through their paces in the real world.


## Conclusion

Developing a new system yourself allows you to tune everything to your liking. It also lets your developers build the system the way they want and learn how it works as they put it together.

Taking advantage of existing solutions like BigCommerce also has benefits. It’s cheaper, quicker and many have tested the solution.

[fabric](http://fabric.inc/) specializes in microservices, and its solutions can help you make the switch easily. Its products are API-driven, allowing you to extend fabric core features easily and grow your services as your business expands.