Lessons Learned from Building a
High-Traffic Express Webapp

NodeConf Barcelona 2015

Patrick Hund, software developer at mobile.de

Germany's biggest automotive ecommerce platform

part of since 2004

10.81M visitors / month

(AGOF Digital Facts 2015-06)

~300 requests / second

Breaking the Monolith

Service-oriented Architecture (SOA)

Service-oriented Architecture (SOA)

Lessons Learned

Bad Example – do not do this!

config.js


const path = "./makes.json"

export default {
    path
};
                        

makes.js


import config from "./config";

const data = require(config.path);

function get(segment) {
    return data[segment];
}

export default {
    get
};
                        

makes-test.js


import chai from "chai";
import makes from "./makes";

chai.should();

let result = null;

describe("When I use the makes module", () => {
    describe("to get car makes", () => {
        before(() => result = makes.get("cars"));
        describe("the result", () => {
            it("is a list of car makes", () => {
                result[0].name.should.equal("Abarth");
                result[1].name.should.equal("AC");
                result[2].name.should.equal("Acura");
            });
        });
    });
});
                        

Good Example

config.js


const path = "./makes.json"

export default {
    getPath() {
        return path;
    }
};
                        

makes.js


import config from "./config";

let data = null;

function init() {
    data = require(config.getPath());
}

function get(segment) {
    return data ? data[segment] : null;
}

export default {
    init,
    get
};
                        

makes-test.js


import chai from "chai";
import sinon from "sinon";
import config from "./config";
import makes from "./makes";

chai.should();

let result = null;

describe("When I use the makes module", () => {
    describe("to get car makes", () => {
        before(() => {
            sinon.stub(config, "getPath").returns("./test-makes.json");
            makes.init();
            result = makes.get("cars");
        });
        describe("the result", () => {
            it("is a list of car makes", () => {
                result[0].name.should.equal("CarMake1");
                result[1].name.should.equal("CarMake2");
                result[2].name.should.equal("CarMake3");
            });
        });
        after(() => config.getPath.restore());
    });
});
                        

Patrick Hund
Software developer at mobile.de

Follow me on Twitter: @wiekatz

Slides available on GitHub: pahund.github.io/lessons-learned

Visit the eBay Technology Europe blog: technology.ebay.de

Cross stitch headlines made with Photofunia