, 14 tweets, 2 min read
10 reasons why I love AWS Step Functions so much, illustrated using a JavaScript Promise chain:

step = json =>
service(params)
.then(flakyService())
.then(longService())
.then(({ id }) => Promise.all([send(id), audit(id)]))
.catch(log)
1. You can think of Step Functions like `map`. The above takes json and returns json. They can feel like pure functions which makes unit testing straightforward.

map([🐮, 🥔, 🐔, 🌽], cook)
=== [🍔, 🍟, 🍗, 🍿]
2. service, flakyService, longService, send, audit, & log are all microservices. We orchestrate all of them into 1 function. Serverless & Server REST, on-prem SOAP, a 10 minute batch service, and a Kafka Message Queue message logging all wired together in 1 flow, 2 in parallel.
3. All errors for the entire set of services and issues that could occur in the orchestration is found in 1 place:

`.catch`

Optionally, you can look at specific logs for 1 service to dive deeper.
4. Each `.then` by default passes the JSON to the next in line. However, you can optionally do error handling. Want to retry 3 times with a "timeout" error, but give up on a "null pointer"?
5. `Promise` has built-in try/catch. Step Functions also are one big try/catch. If your Lambda, message Queue, Batch server, whatever throws an error you don't understand, no worries, it's caught.
6. Promises handle synchronous and asynchronous code, so too can Step Functions. Promises can chain together other Promises. Step Functions can chain together other Step Functions.
7. Sometimes it's good to do 2 things at once. Promises can be run concurrently using `Promise.all`. Steps can also be run concurrently. Like a Promise.all, the step will complete with all the results in an Array. Entire Step Functions as a whole can also be run concurrently.
8. Data lenses! The Promise `then` callback allows you to return data or a Promise. The above example destructure's the `id` for use in 2 Promises. Step Functions allow you to destructure both in the response & in your parameters. Basic lenses like Lodash get or Ramda view.
9. Using the AWS Console, it's clear what the input JSON was and what the output JSON was. Each step has what the JSON was at that time, allowing basic tracing of your data over the entire execution of your orchestration. If something fails, you can see exactly where and why.
10. Step Functions have API's provided by the AWS SDK to query everything about them, start them, see their status, see how many are running and built API's and UI's around it.
As a Functional Programmer, having pure functions orchestrated with non-determinsitic downstream services in a predictable way without a care in the world about side effects... is just amazing. I can answer this in about 10 seconds: "Did it work? No? Who failed? Why?"
You add more deterministic Lambdas around your other services with simple JSON inputs and known Errors that you can effectively use matching syntax on gives you insane control and peace of mind over a lot of disparate services.
I was so excited, I didn't proofread my JS, lelz, should be:

step = json =>
service(json)
.then(flakyService)
.then(longService)
.then(({ id }) => Promise.all([send(id), audit(id)]))
.catch(log)
Missing some Tweet in this thread? You can try to force a refresh.

Enjoying this thread?

Keep Current with Jesse Warden

Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread 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!