Pepperoni Papaya
Pepperoni Papaya

Reputation: 113

How should I divide up my cloud functions?

Currently I'm deploying my whole express app as one cloud function on Firebase. Something like this:

// index.js
import * as express from "express";
import api1 from "./controllers/api1";
import api2 from "./controllers/api2";

const app = express();
app.use("/api1", api1controller);
app.use("/api2", api2controller);
export const app= functions.https.onRequest(app);

// controllers/api1.js
import * as express from "express";
const router = express.Router();
router.get(...)
router.post(...)
export default router;

It's very convenient especially if you want to move your existing express app to cloud function. However I'm thinking about breaking it down and deploy each controller as their own function instead. Something like this

// index.js
import * as express from "express";
import api1 from "./controllers/api1";
import api2 from "./controllers/api2";

const app1 = express();
app1.use("/", api1controller);

const app2 = express();
app2.use("/", api2controller);

export const app1= functions.https.onRequest(app1);
export const app2= functions.https.onRequest(app2);

At the very least, this improves transparency, when I go to firebase console, I can see that I have 2 controllers, how much activity is going on in each one, and check their separate logs.

Is there any performance or cost issue that I should be concerned about?

Upvotes: 0

Views: 283

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317352

There are no significant performance concerns here.

Upvotes: 1

Related Questions