0:00 All right, so let's go ahead and get started by creating our new 0:02 Nest.js 0:03 application. In this project, I'm gonna use Bun runtime, 0:07 which comes pre-built with the Bun package manager 0:11 and the Bun runtime, which are both much faster than any other 0:14 package 0:15 manager or the Node.js runtime, especially when running 0:19 Express. If you wanna follow along and use Bun as well, you can use 0:22 my Nest Bun package that I've created to 0:26 bootstrap a new Bun application with Nest.js. 0:30 For this, simply run Bun create at Nest Bun and call 0:34 it whatever you'd like. I'll call this Nest.js Workflows, 0:38 and this will run with the Express http 0:42 adapter. You can also choose to run with 0:45 Bun.serve natively, but let's stick with 0:49 Express as it offers better support for the moment. 0:53 So we'll go ahead and confirm that we'll start with Express. 0:56 If you do prefer to use normal Node.js, you can simply 1:00 also run Nest New 1:03 and call this Nest.js Workflows. This will start your application 1:07 with Node.js runtime and your manager of choice. 1:10 I'm gonna stick with Bun throughout due to its great speed and 1:14 developer-friendly experience. 1:16 So now we've successfully initialized the project. 1:19 We can CD into it, 1:21 and I can run Bun dev to start our 1:26 local server. 1:28 And now if I visit this local host three thousand URL, 1:32 we have our standard "Hello, world" 1:35 response coming back from our default app controller in our 1:38 application. So let's go ahead and open up this new Nest.js app 1:42 in VS Code to take a look at it. All right, so now we have the 1:46 default starting Nest.js application that Nest 1:50 Bun comes with out of the box, which looks very similar to any other 1:53 Nest.js 1:54 application. We have our package JSON with our starting 1:57 scripts to start our development server, to start up the app, and 2:01 recompile when there's any changes. 2:03 The nice thing about Bun is that we can provide it TypeScript 2:06 directly. 2:07 There's no compilation that actually has to happen. 2:11 Instead of having to compile to JavaScript, we can point directly 2:15 to TypeScript, which is a very nice developer-friendly 2:19 experience. 2:21 The rest of this application just looks like any other starting Nest.js app. 2:25 In our main TS file, we are creating the Nest application 2:29 with the Nest factory passing in the root app module. 2:33 We're also m-- taking advantage of Nest.js twelve 2:37 schema validation using Zod, which allows us to define 2:41 our schemas and DTOs using Zod schema validation 2:45 library directly, which is very nice. 2:48 And we're starting up the http server here on port three thousand. 2:52 Finally, our app doc controller has a single get 2:55 route. 2:56 This is the "Hello, world" sub string we saw on our local host 3:00 three thousand, and we have a sample post route showing 3:03 our Zod 3:04 schema validation in 3:06 action. So here, we're extracting the http request body 3:10 and pointing the Zod schema here to this greet schema. 3:15 So this comes from our app schema. So you can see this is a Zod 3:19 schema where we define a name using schema. 3:25 And we can even define types from it. 3:28 And then by providing this to the schema in the body 3:31 decorator, Nest.js will automatically validate this 3:34 on any incoming 3:35 request and make sure that the body adheres to this schema, 3:39 which 3:39 is very nice in the latest Nest.js versions. 3:42 And then finally, we're also injecting the app service with 3:46 our single 3:46 get "Hello" sub string response. So we have our starting 3:50 Nest.js application working out of the box with Bun package 3:54 manager and Bun runtime. Of course, to install our 3:57 dependencies, we just run Bun install, and you can see how fast that 4:01 is. 4:02 So now we have the server and ready to 4:06 implement our workflows. Let's go ahead and get 4:10 started with installing the dependencies that we're gonna need for this 4:14 application. All right. So let's add the dependencies we're gonna 4:18 use 4:18 for this project. For this, we'll use Bun install and then list the 4:21 dependencies we're gonna need. 4:24 For this, we're gonna use the new Nest.js Drizzle 4:26 package, which, 4:28 uh, offers a very nice integration with 4:31 Drizzle 4:31 ORM directly inside of Nest.js. Drizzle ORM is how we're 4:35 gonna connect to Postgres and map our TypeScript code to the 4:39 underlying database operations. 4:42 I'm also then gonna go ahead and add, of course, the new Nest.js 4:46 workflows dependency, which is actually going to allow us to create 4:50 these 4:50 distributed workflows. 4:52 I'll then add Drizzle ORM as well. 4:56 PG for Postgres. We're gonna use Postgres. 4:58 So this is the underlying dependency that establishes the connection to 5:02 Postgres, 5:04 and this should be all the dependencies that we need. 5:07 I'll also install development dependencies at 5:10 type/pg. 5:13 Drizzle kit, which we'll use to generate database 5:15 migrations, and 5:17 this should be enough to get us going. 5:19 So now I'll restart the server, and we should be set with all the 5:22 dependencies that 5:23 we need. Now the first thing I wanna do is set up our Docker 5:27 compose file. We're gonna use Docker to 5:31 actually run our dependencies in this project. 5:33 In this case, all we're gonna need is a Postgres container running. 5:38 So for this, make sure you have Docker Desktop 5:40 installed and running. 5:42 I've installed Docker Desktop on my machine. 5:44 And then we're defining a Docker compose file with our services. 5:48 So these are the containers that we're gonna run. 5:50 In this case, we just need a single Postgres container 5:53 using 5:54 Postgres 18. I've also defined some environment 5:57 variables for 5:58 us, setting the Postgres user password and default database 6:02 all to workflows. I've also set up a ports 6:06 array. So here, this will map our port 6:10 on our local machine 5454 to the 6:14 port running in this container 5432. 6:17 This is the port that Postgres listens for for new 6:19 connections. 6:21 So this will allow us to establish a connection to the Postgres 6:24 database from our local machine, and that's how our application 6:28 will connect, which is excellent. 6:30 And then finally, I've also just set up a volume pointing at 6:34 this 6:34 PG data. We specify this empty vol bottom here. 6:38 This volume then maps to the container path here, 6:42 and this is where Postgres stores its data by default. 6:45 And what this does is allows our Postgres data to be 6:48 persisted even once the container is shut down. 6:52 Now, this is gonna be very convenient in this 6:54 lecture because the whole 6:56 point of this NestJS workflows, as we'll see, is that it's all 7:00 gonna be persisted inside of Postgres. 7:02 This means that even once we start a workflow, if 7:06 our container goes down or application crashes, 7:11 well, that is okay. The whole point of NestJS Workflows is to 7:14 provide a durable 7:17 distributed transaction such that if our application 7:21 crashes before, after, or in the middle of a workflow, we 7:25 can resume it elegantly without any issues and this works 7:29 because we store our workflow data inside of Postgres. 7:33 This also allows us to run the workflow in a distributed 7:37 fashion where we can have multiple copies of our application 7:41 running and processing these workflows in parallel. 7:44 And so this gives us this distributed nature for the workflows and allows us to 7:48 process multiple workflows in parallel, giving us much higher 7:52 throughput. 7:53 And so this all works because Postgres acts as the central store 7:57 that multiple copies of our application can connect to and 8:01 read the workflow data. So this will be key, 8:04 and we'll see this data later 8:05 on as we debug the workflow inside of our application. 8:11 So now that we have this Postgres container defined, 8:15 make sure you start it up inside of another terminal. 8:18 So to do this, I've launched another terminal 8:20 and cd'd into our project 8:22 directory, and I'm just simply gonna run Docker 8:24 Compose up. 8:26 This will then read in our Docker Compose file and start up the Postgres 8:30 container. So you can see here we're now ready to 8:32 accept connections on port 8:34 5432, which we know we can connect to from our 8:37 local 8:38 5454 port. So this is great. We now have Postgres running and 8:42 available to connect to. Next up, let's go ahead and set 8:46 up our database connection inside of our 8:49 NestJS code so we can connect to this database. 8:53 Then we'll set up Drizzle ORM and finally set up NestJS 8:57 Workflows to actually integrate with Drizzle ORM and the 9:00 Postgres database. Let's go ahead and do this next.