DEV Community

Cover image for I Built a Production E-commerce System — Here’s What I Learned
Modern Web
Modern Web

Posted on

I Built a Production E-commerce System — Here’s What I Learned

E-commerce projects at first glance look simple — search products, add them to a cart, checkout, complete the payment, done.

I thought the same. I recently built an e-commerce system, and it started with the simple problems we all know. But when I started questioning how the actual system works in production, I learned so many things that I think you would find helpful.

Why an e-commerce project?

Most of us think of an e-commerce project as a beginner project and categorize it as boring. But if you think about it, e-commerce is one of the best projects that covers most of the topics a beginner needs to start with full-stack development.

  • Frontend storefront
  • Backend APIs
  • A dedicated Content Management System
  • Secure authentication
  • Protecting user data with proper authorization
  • Database design
  • Inventory system
  • Concurrency
  • Order lifecycle
  • Data responsibility
  • Webhooks
  • Payment lifecycles
  • Security
  • Business protection

And much more.

What I learned

When I started asking questions about how an e-commerce system behaves differently in production, I encountered quite a few problems that were fun to tackle.

Inventory isn't just a number

Inventory management is something that most beginners overlook while building an e-commerce system. I learned that e-commerce inventory is more than just a simple stock - qty at the end of checkout.

A correct inventory manager makes sure that the system does not sell a product it doesn't have and does not take orders when products are out of stock. It also needs to prevent overselling caused by inconsistent inventory or race conditions.

Cart looks easy until it isn't

The cart is a common feature in any e-commerce project. It is very easy to make — at least, that is what I thought when working on it.

But when I followed the production rule of keeping it simple and storing the bare minimum data, things started to get a little tough.

You never trust the frontend in production. So, validating the cart at every update, managing a local copy in localStorage, and syncing it with the database on login includes a lot of moving parts that aren't obvious at first.

Order failure does not mean no payment

A very important lesson I learned while building the project is that an order failing does not mean that no payment was processed.

While working on my cart sync, I discovered an edge case that gave me a checkout that was kind of faulty. I will discuss it some other time, but the result was that the payment was processed while the order failed.

The problem:

The customer paid, but no order was placed.

This taught me that it doesn't matter whether you place an order or mark it as failed, the system should always keep track of payments. This helps admins and support teams identify what happened and refund the customer when necessary.

Production

When an e-commerce system is running in production as an actual business, the payment processing and getting an order becomes just the first part of the system. There is much more involved:

  • Checkout failures
  • Payment disputes
  • Business protection from fraud
  • Customer data privacy
  • A working support system
  • Background workers to clean up database noise

The interesting part is that when developing, you will rarely face these issues. Your main focus is usually on making the checkout work successfully.

You won't think much about checkout failures, payment disputes, or how to identify suspicious users to protect the business. You won't even think about building a support system or background workers to keep the database clean.

All these things become important when the project is actually running in production.

The bigger lesson

Building this project taught me how different production is.

Making a feature is easy, but production forces you to think about how that feature can break and what you can do to prevent it from breaking.

The difficult part is not just coding the successful paths. It is figuring out where the system can break and making sure that doesn't happen in real-world use.

And the most important thing I learned is that in production, it is not just an e-commerce project. It is an e-commerce business.

Every action the system takes reflects on an actual business, and as developers, we need to make sure the system protects the business and helps it operate properly.

Want to see the project?

I would love it if you guys could test my project and maybe try to break it. Give me feedback and share where you think it is lacking so I can improve it and learn more.

Live Project: https://go.modernweb.in/GexIq5

I also have a full project tour published on YouTube. You can check it out if you're interested.

Project Tour: https://youtu.be/-TEatao1HsQ

Thank you for reading this article!

Top comments (0)