PocketBase First Impressions (Code, Example, Deployment, and more!)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if you've ever been using Firebase and you've come to the conclusion you know this is really great but I wish it was just kind of how do I put this better today we have the solution the solution is pocket base so this morning for the first time I booted up pocket base this is something I've been wanting to try out for quite a while today I finally got around to it and I went ahead and built a tiny little example app I host I self-hosted a whole custom deployment of it added my own API wrote dockerized it did all this stuff so today I kind of want to break down my sort of First Impressions using it how it felt the sort of DX I have a full demo I'm open sourced all of it so down below you'll get a link I have a git repo that contains a fully built out demo of pocket base and a little react app that's using some authentication I didn't go too deep into the client-side demo because that's not really the point of this video and honestly the point isn't even to get into too deep into the crazy features it's more just the first impressions give you a give you a good idea of how this really works and the sort of pros and cons of using it so before I go deeper into all of that make sure that you guys if you are not already that you hit subscribe we are going to be doing tons and I mean tons more golang content over the next couple months all the way through February 28th we're gonna have something brand new every single day so make sure you guys are subscribed for that and without further Ado let's talk about pocket base so when you land on the home page for pocket base you're gonna get this really nice little landing page and if we go into the documentation something you're going to notice that's a little different from a lot of these platforms you're probably used to is there's no like login button there's no sign up and the reason for that is because in order to host pocket base you have to do it yourself and when I first booted this up and first messed with this I was kind of confused for a while because you're going to realize very quickly that this isn't this doesn't work the way a lot of traditional things work and it's a little different but I think that the different is good it's good different so if you go to Firebase you have to log in here and here we just get open so or stocks and we have to actually either download the executable or actually run it through a custom Go app so one thing to note before I get too deep into this is this warning up here this is still in active development and it's not at 1.0 yet it is a super super promising technology but again we're not it it's not fully deployed yet so I wouldn't use this in production or anything super critical but it's absolutely something worth investing your time in to kind of mess with because I think when we're in the future when I'm trying to do some super quick MVPs or if I need to do something smaller scale like run an email list or something this is a really great solution for that I wouldn't run some Enterprise grade app on this but if you're trying to run a side project or some smaller scale internal thing this is a really really promising option that I think does what Firebase does but better and the reason it does it better is because a it's open source B it's going to be way faster because of the way it's set up so under the hood pocket base is using sqlite and this will make it super super performant if I go into this over here so this is my Live Pocket based console I'll talk about this more later but sort of what we're going to get here is you're going to see all of this data is being hosted within a sqlite instance on my back end what's unique about sqlite is it's not it doesn't work the same way that postgres or MySQL does in that you would have like a separate database instance this is just being run on a little storage bucket within my app so when I'm hosting this app well first of all it can't be serverless so that is one thing that you have to take into consideration I mean I guess you could maybe Wrangle it and like point it to a static server but you're not going to do that on pay in reality it's going to be servers this is going to have to be deployed to a server that's going to be constantly running and the reason for that is because we need to spit up our CPU our Ram all that stuff but we also need to spit in up a volume of storage which is where our SQL light is going to go so instead of going to some separate instance of our SQL or my our MySQL or postgres instance or whatever that's going to be run on disk which is actually going to make this really really fast so they say in their FAQ that they're not going to support other databases and the reason for this is because sqlite is already performing enough and it'll make it it makes it really easy and quick to set up because all you have to do is just put that little volume on your storage put that little volume into your app and then you host everything there and it's pretty easy to actually deploy all this as I'll show you later on so getting into the actual you know interface of pocket base what do we what does it offer for us so it gives us first of all it'll give us user management so here you can see a list of all the users I have I made these two fake users and this is actually my production instance so this will be deleted and takened out before this video goes live but right now you can see this admin page I have these two fake users that have this test collection if I wanted to create a new collection I can go in here I can pick out what Fields I want let's say I want to have a number field and we'll call this age and then make a minimum is zero Max is ten thousand a thousand or something make sure it's Unique you know this is dumb it doesn't actually matter put in a post name and then we can create this so then we're gonna have this new collection with all of this stuff in here if we add a new record in here we have to put in our age of this create and then oh it's going to give me my validation stuff here so we'll make that 234 create and there you go so this is very similar to Firebase or super bass or any of these sort of well I guess base products that are out there right now is you have your collections and then you have your users in here here these are just this is just a special collection Within These on the client as I'll show you later you interact with these in a it's a little different than a lot of other ones but I actually kind of like the way they do it they sort of just treat them like another collection so our users are in here over here we can get some nice logs so I'll show you what requests I'm making so on my client I made some requests earlier then we have nice admin some admin panel stuff in here yeah so this will also allow us to do some file uploads so if we don't give it an S3 storage space let's just put them on disk on the disk right now that I'm using and I only allocated a gig for this so I wouldn't want to do that I would want to link some external S3 so you can put all your information in there very simple you can do mail you want to set up like your email server there are a million different Services out there to do that you can sync your data you can set up oauth providers I didn't do that here but this is pretty trivial all you need to do is just go in here enable it and then put in your client ID client secret uh you can get that from Google very simple stuff in here then one of the really nice things they give us is administrators so I have my admin user in here which is me I can go ahead and add a new admin very easy to do so all this stuff just gives us a nice sort of back end as a service this is the basic this will give us the ability to log users in do crud on some data set that we need for our application upload files send emails pretty much everything you need for an MVP in most use cases and it's very similar to Firebase but the difference here is a it's super performant it's written in go B it is super easy to set up and run all you really have to do is just download it and then run it and then see it's going to be really really cheap to host because all you have to do is put it on some instance and as they note within their FAQ without optimizations pocketbase can easily serve 10 000 plus concurrent and persistent real-time connections on a cheap Six dollar VPS so really not that hard just really cheap really easy really great so let's get into the code of an actual example and really dive into what this will do so there are two different ways that you can actually download and run pocket base one of them is you can go to the documentation page so like I did earlier and you can download one of these actual binaries so you just download the binary and then run it via DOT slash pocketbase serve or you can run this through an actual Go app and that's what I like it to do and the reason why I did that is because you can actually use pocketbase as a pseudo framework so if you need to get some custom API routes up in a pinch that go beyond the simple crud from a collection or whatever that's really easy to do so the reason why I wanted to do that is I want to showcase that API route so in here in my main all I have to do is I have to do app colon equals pocketbase.new I'm importing the pocket based package from pocketbase core really basic stuff here then once I've initialized my app the really nice thing that we can do is we can then add stuff to it so I get this pointer to a pocket base instance and then I can do app dot I can do app.on before serve some you know some boilerplate and then the key right here is I am adding a get request right here so now I'm adding to my pocket base instance PB Dash demo API hello this is just a hello world endpoint but you can put whatever you want in here if I go back to to my URL here if I grab this URL then let's paste this over here and if we do PB Dash demo API slash hello and we hit enter we're going to get hello world and that is because we added this custom API route so that anytime we want to extend our functionality it's as simple as just putting some stuff in here now this makes it a little more complicated to deploy but luckily I put together a Docker file for that so all we need to do then is just app add this and then do error colon equals app.start log dot fatal you know normal stuff so we start our app here to run this in Dev all we need to do is we just need to do I made this task file someone recommended this earlier super really cool this is like make but nicer so basically all you have to do is go run main.go pass in the serve argument and then pass in where you want to host it so I'm just going to do task start when I do that it'll take a moment it takes a minute to warm up here because it's building a pretty massive application but it builds within a second or so and then I can go to localhost at 8080. then this is my admin page I could log into this and it'll be the same thing that you see up in prod so you're going to get the same instance in local and prod the only difference is what the underlying data is and you need to make sure that that underlying data is safe and secure which is one of the big things because it's not a separate database instance but as long as you have like backups on for your volumes you're good um and I I could do a deeper dive on this later if you want me to but so I put all that together here very simple to get this server up and running and then really the cool stuff here is that's it so this is ready to deploy before I go over to deployment I want to kind of talk about the client app I put together here and then we'll go ahead and talk about deployment and then my sort of thoughts so first of all the client so the client itself right here this is just a very simple Veet react app I um the old the front end I'm most verse I'm best with is reactive is how it is so all I did is I set an environment variable here which is just the URI for my pocketbase instance here I have it set to um pocketbase first impressions.fly.dev you'll notice that that matches this up here so all we have to do is set whatever we wherever we want this to be if you're in localhost the readme has instructions on how to do all this but you can set your um if you set it to be 127.0.0.1 colon 8080 this will link it to this so this local instance running right here so that'll connect it there all you have to do is just pass in whatever you want to B is the easiest way to put this in prod would just be to have this as an environment variable and then you switch it out based on your environment pretty simple stuff then within our app all we need to do is just create a new instance of pocket base they provide a really nice JS SDK right here we just do PB equals new pocket base we import our environment variable and then We're Off to the Races so all I did down here is I made a stupidly basic react app I have this down here so basically all the app is it just has um we're just checking whether or not we're logged in so I'm going to do pb.ausstor.isvalid you're gonna have to plug this into State yourself this is not a front end video or a tutorial on how to do front end stuff but it's just something to keep note of then we go to this we're going to get email password so we look back at the code here really this is just basic react form stuff nothing important here right now we're logged out so what I'm going to get is this form I have my state up there then the key is going to be this sign sign up button so let's start by signing up so what we're going to do if you've ever used Firebase is this is very very similar we're going to do pocketbase.collection we're going to get users then we're going to create a new user the fields you have to pass in here are the email password and then the password confirm so if I go ahead and just put in test at test.com and I'll just put in a password whatever it is I don't really care then we hit sign up this will go ahead and it'll take away moment here but then it's going to say you are now logged in I hit OK and it'll say logged in so what's actually happening there is I'm just running a chain of callbacks basically I just do pb.collectionusers.create dot then I want to then once I create the user I need to sign in to the user so I do pocketbase.collectionusers then I auth with password pass and email and password then finally I say we're logged in and set logged into true now in the real world you would probably want to wrap this in like a react query type thing make this a lot nicer I find that front-end callback Health stuff gets really gross but this is a super basic example and this is not a front-end video so yeah that's all you need to do to actually sign up then logging in is as simple as you just need to pass an email password and then do um yeah you just do auth with password email password and then back up here within our logged in function we just have a pb.au store.clear which is going to set us to logged out so I go ahead and hit log out we're going to be logged out so this is some really basic stuff the way you would read and write out of a collection is about the same this is not a super detailed tour this is not a tutorial on how to actually mess with like the client stuff that's just to give you an example of how it works the documentations in here are the documentation here is excellent um no real issues it's pretty simple if you've ever used Firebase or any library that messes with data this will still make a lot of sense to you not a big deal so that's all I really have for the client so let's talk about how you build and deploy this this is one of the most interesting things and I think one of the things that's at least for me mentally was kind of tricky to wrap my head around as I get it I get it it's pretty easy but at the time it was weird so the first thing we need to think about is we need to actually take our little main.go which is going to have our pocket base instance and we need to put that up onto some sort of cloud container image for this tutorial I'm going to be using fly.io this is their homepage this is a really nice little quick deployment uh platform it's kind of like uh I would probably rate this in between like this is closer to an AWS type thing it gives you more control but it's still very user friendly very nice to use super DX focused um really like their stuff and I want to just use this to deploy so what I did in here is I was able to create a new instance I have all this stuff up here um I've this is not going to be a deployment tutorial but I have I linked the guides that I followed in basically all I have to do is set up fly then once you've set up fly you can just follow the stuff I have within the readme here which is basically just you need to install the command line initialize the app create the storage volume and then upload it so we're going to be uploading this to fly control and the key things that we need to have here is we need to have a way to compute and run our app and then we need a storage volume for apps so if you look over here at my dashboard I have volumes and this volume is going to contain my database and my SQL and all that stuff so we're well my SQL as in MySQL not MySQL as in MySQL you get what I mean so this in here is going to contain the sqlite instance this is the persistent storage that as I deploy over and over again it's not going to overwrite the storage this will persist throughout forever if the app crashes this will not go away and that is super important because we have user data and client data on there we can't lose that we can't lose that data so this needs to persist in a separate volume So within our fly.tobble you can go ahead and just create that and then Mount I'm mounting PB data to app slash PB data and if you look within my local instance here I have this directory PB data this is what uh pocketbase is going to create every time you run it to store all of the data so this data.d B contains all the information from my local pocket base instance so that's where all that's actually being stored so with all that said we need to go ahead and build our app I did that with the docker file you can just use this nothing fancy here all I'm doing is just creating a goaling instance adding some basic build tools that we need in here stuff like GCC and stuff like that I go ahead and set my work directory to be app I copy in my god.mod and sum I go ahead and download all the packages that usually takes a minute because there's a lot of them then we go ahead and copy all of our go files in this case there's just one I build it and then I set my output binary to be PB Dash build I expose 8080 and then finally we run this with Slash app slash then we finally just run this with Slash app slash PB build serve and then we want to bind this to localhost 8080 you actually don't need to use a dynamic port on fly fly is really nice that way you can just specify down here that our internal Port is going to be 8080 so I don't have to actually go in and read some environment variable it just works so that's how we are actually building our app then once we have it built all we need to do is uh fly CTL deploy and it will deploy our app so once it's deployed we will have our storage allocated our app generated and built um one key thing to note here is I have my work directory is app so that means that my pocket based instance is going to be app slash PB build that means that I need to make sure that my storage is in the right directory and that's the reason why we're adding a mount here that says the destination is slash app slash PB data because remember our pocket base instance is going to be in that app directory we want to make sure that we have a mount to our data store here that's going to look just like this within there because when we actually create this volume this volume name of PB data that's going to be just mounted in whatever void they put it in I don't really know under the hood but we need to make sure that that Source goes to the right destination otherwise nothing too fancy it'll get deployed it'll do all the provisioning for us and if we just go to the URL it gives us here it's going to get a not found but all we need to do is slash underscore and we will be on our admin page so that's the sort of General overview of pocket base getting it deployed doing all that stuff super easy Once you sort of wrap your head around it and I think this has huge potential so with all that said getting into my sort of thoughts on this I'll be sort of brief here but I think that this has tremendous potential for the future obviously it's not ready to be used yet as they say within their documentation that is in active development backward compatibility is not guaranteed wait a little bit before we really use this but I think that this has tremendous potential to be that sort of I think that'll fill the Firebase Niche super well because I think for me the sort of place I've landed on my opinion with Firebase type Services is if you're going to have a super complex app that needs to scale big time and do really crazy stuff you don't want to be using some really cheap crappy nosql light database type thing if you no SQL is not bad I think nosql databases are good like mongodb or Dynamo but are if you need a nosql database for like a serious load or something like that you don't want that to be in Firebase so I think that Firebase sort of falls in the realm of if you need to do something quickly and easily you want to just throw something up in a week and get a minimum viable product out there to test an idea test a new startup get an email list out there something like that I think that's where the sort of Firebase Super Bass stuff comes in really well I think pocket based slots beautifully into that Niche and honestly I think it does it better than the other two I think that Firebase and Super Bass for where I would use them they're kind of Overkill I don't need them this super lightweight super easy to use super clean and fast go instance with a sqlite database that I can host myself in a tiny little six dollar droplet that's what I want to use that's so much better than dealing with all the crap with Firebase because I don't want to scale an app with Firebase and I wouldn't want to scale an app with pocket base but it's great for the sort of Niche it fits into where you have I think these I think competent devs who really know what they're doing and want to take shortcuts I wouldn't learn on this I wouldn't learn back-end development on pocket base or Firebase or super bass or anything stuff and I'll talk about that in another video but I would personally really like to use this for prototyping if I want to put out a prototype and this is where I do it so getting authentication database file storage and an admin dashboard done in about five minutes once you know what you're doing and you have this template and you guys now do because I put it together and really this only took me a few hours I started this around uh let's see it's five right now I started this around three I mean it took two hours it was not hard at all it's really basic stuff but it's still extremely powerful and I think extremely worth your time so if you are a back-end Dev and you're looking for some super lightweight solution I highly recommend taking a look at pocket base give it a try also give fly a try I have been using them more lately think that this is a really nice hosting platform I'll probably put more back ends on here um them and Railway and some other stuff are really great platforms I'll talk about hosting in the future but uh as far as my verdict on pocket base really cool stuff really bright future and I'm excited to see where it goes so hopefully this helped you out if you made it this far thank you as always have a great day
Info
Channel: Ben Davis (Davis Media)
Views: 22,447
Rating: undefined out of 5
Keywords: Go, GoLang, PocketBase, Firebase, Supabase, Programming, Web Development, Backend Web Development
Id: Hk-Sy_pE7L4
Channel Id: undefined
Length: 20min 47sec (1247 seconds)
Published: Fri Jan 13 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.