Multiple services or multiple files?

In the doc I see :

… as your application grows, you can break it out into multiple services.

and later this

users/
  serverless.yml # Contains 4 functions that do Users CRUD operations and the Users database

posts/
  serverless.yml # Contains 4 functions that do Posts CRUD operations and the Posts database

comments/
  serverless.yml # Contains 4 functions that do Comments CRUD operations and the Comments database

Why is this setup/organization better than this :

# services.yml
[..]
functions:
  orderFunction1
    handler: orders.orderFunction1
  orderFunction2:
    handler: orders.orderFunction12
  cartFunction1
    handler: carts.orderFunction1
  cartFunction2:
    handler: carts.orderFunction12

and then

  • orders.js that contains orderFunction1 and orderFunction2
  • carts.js that contains cartFunction1 and cartFunction2


Simone

Each Serverless project is deployed as a single CloudFormation stack. CloudFormation has a limit of 200 resources in a stack. Once you hit that limit you need to split your project into multiple projects. If there’s even a slim chance your project is going to exceed the 200 resource limit it’s be better to plan for it now instead of being forced into a restructure after you’ve hit the limit.

PS: I know 200 sounds like a lot but depending on how you have your functions wired up you’re looking at 20-40 functions per project.

1 Like