, 12 tweets, 2 min read Read on Twitter
You know my "functions don't call other functions" mantra?

I stand by it.
Functions shouldn't call other functions in almost every scenario

They can, but they shouldn't.
Not to say that there are some specialised scenarios where it's *really useful* for you to call another function directly! There are.
But if your *overall architecture* is lots of functions calling functions then I would suggest very strongly that your architecture is probably going to have problems
The most common scenario I've seen where the "functions call other functions" applies is...

...coding functions as microservices

This is a bad idea
Why is "functions as microservices" a bad idea?

Many reasons, but mainly because your not using your function scaling efficiently.

Each part of a microservice should be it's own function and should scale independently.
I've seen multiple companies do this, and I don't get where the idea comes from.

Unless the idea is simply "they're just small servers so let's transfer our microservices ideas over"

And that's unfortunately not that helpful
When I first saw Lambda, I immediately saw the point of separating out functions. My first attempts were more "microservice-like", but very quickly separated out due to recognising that different elements required different scaling behaviour.
And different scaling behaviour affects data layers too.

Which is why shifting your ideas of "microservices" to functions doesn't work again.
So when should functions call other functions?

When you *really* need to use certain types of functionality within your application... e.g. fan out, or you need a response from a function that a unidirectional flow doesn't allow, or isolation of *specific* functionality.
Exceptions... not the rule.

Which is why I always tell people "functions don't call other functions"

It's very simple.

Break it *** when you understand it ***

If you don't understand it, then don't break it. You'll thank me in the long run.
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Paul Johnston
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!