I replaced my entire tech stack with Postgres...

Fireship · Intermediate ·📊 Data Analytics & Business Intelligence ·1y ago

Key Takeaways

The video demonstrates how to use PostgreSQL as a replacement for multiple tools in a tech stack, including in-memory cache databases, cron services, and authentication systems, leveraging its advanced data types, extensibility, and ecosystem of extensions. It showcases 10 unusual ways to use PostgreSQL to build full-stack applications from scratch, including using Postgres as a time series database, implementing row-level security, and automatically turning the database into a RESTful API.

Full Transcript

modern web development sucks we have amazing tools that solve every problem and technically it's never been easier to build a billion dooll failed app idea the problem is that by the time you deploy it you end up paying 20 different ycb startups to use their fancy shovels you think you need an in-memory cache database to handle your low to five users you need a cron service you need authentication performance monitoring analytics serverless functions and the list goes on it's no coincidence that America's homeless population started to rise immediately after the release of nextjs in 2016 but what if I told you you could throw all of these shovels in the incinerator and use nothing but postgressql yes the relational database to achieve 90% of your web development needs in today's video we'll look at 11 useful unorthodox and just plain weird ways to use postgress by the end of it we will have built a full stack application using nothing but an open source database but first of all what makes postgress special and why not use something like MySQL or SQL light well out of the box postgress provides Advanced Data types like binary Json arrays key value stores and even geometric types to Define shapes but more importantly it's extensible and you can even create your own custom data types over the years this has led to a massive ecosystem of extensions where developers have given it all kinds of crazy new features it's just like modding a game where you take something that sucks like Civilization 7 and install a bunch of mods to make it playable now before we get into the first example I first want to warn you that just because you can do something in postgress doesn't mean you should before you go and cancel all your shovel subscriptions don't forget to think critically and make sure you use the right tool for the job one of the great debates among web developers is SQL versus nosql and one of the key selling points for no SQL is that you can work with unstructured data like objects with Dynamic data that might be different for each record you can't do that in SQL because every table has a fixed schema well actually that's not true because postgress supports binary Json in this query you'll notice how we create a table with a Json B type and then insert some values into it as raw Json strings so pretty cool and believe it or not we can actually query this data now we can use a select statement followed by a wear clause and then this syntax to filter and access Fields inside this unstructured data that feature is built right into postgress but now we're going to implement some really crazy stuff thanks to extensions first though you might be wondering where do I get a postgress database it's free and open source to host locally but an even easier option is neon the sponsor of today's video they may not condone all the crazy stuff I'm showing you in this video but they provide postgress on a serverless platform that makes it really easy to Kickstart and scale your projects not only do they have an awesome free tier but there's also developer friendly guides for all the biggest Frameworks and OMS developers already love postgress and neon makes it even easier to work with by providing features like branching which allows you to easily create different data workflows for development testing and production and will automatically scale up with zero effort as your app grows give neon a try for free right now using the link below to create a postgress database then take your connection details to a VSS code extension like SQL tools and connect to it locally and now we're ready to do some really crazy stuff with extensions developers only want one thing and it's disgusting a Chron job which is code that runs on a schedule now normally you would have to edit the cron tab file on Linux to achieve this or pay a sass to do it for you but postgress will actually give you a Cron job for free if we install the PG cron extension we can then write a SQL statement that runs a KRON schedule give it a name Define the schedule and then it will run the SQL statement on that schedule like you might want to delete or aggregate a bunch of data on a daily basis that's cool but another thing you think you might need but probably don't is an in-memory cache database like reddis or mcash well in postgress you can create your own po man's redus by using an unlog table as a cache this prevents right ahead logging where changes to the database are written to a log file before being applied to data files and that provides the D for durability in asset and that means if your server crashes unexpectedly committed transactions will not be lost however you don't really need that for a cache and disabling it provides better performance then you can update the postgress config to store it in a shared buffer which will keep the data highly available in Ram and then summon the autov vacu demon to avoid bloat and maybe throw in PG KRON to automatically delete any entries with an expired time to live but this wouldn't be a proper fireship video if I didn't mention Ai and if you're building an AI app that uses rag stack you might consider paying for a vector database but what you could do instead is just install the PG Vector extension it provides a vector data type that allows you to store multi-dimensional data then you can do things like make a query for nearest neighbors based on L2 distance and you can even take things a step further with the pgai extension not only does it handle Vector embeddings but it allows you to load your own data set and vectorize it all entirely in SQL code but speaking of vectors A more traditional feature you might need is a full Tech search engine where users type into a search box and get results even if they have typos the postgress actually has built-in support for this with the TS Vector type it'll take a string like this and break it up into a bunch of smaller parts then we can create a generalized inverted index for better performance which gives us the ability to then Rank and query the most likely results from the data using double app which is the tech search operator and now you don't have to pay for expensive tools like algolia or elastic search if you're sick of writing SQL code though one thing you might do instead is use graphql the magic PG graphql extension can transform your database into a graphql API and that makes it incredibly easy for any programming language to understand in query your database just add the extension and then start writing graphql resolvers directly in your SQL code and best of all no additional servers libraries or paid SAS middlemen are required but what if you're building a real-time application using tools like Firebase or superbase that's a difficult feature to roll out on your own but a library called electric SQL fixes this it's not a PG extension but rather a sync layer which would sit in between your database and your front end code to ensure that the end user always has fresh data and that means you don't have to mess around with websockets or write a bunch of broken code to automatically fetch data when it changes and as an added bonus it works great with neon but another thing developers like to brag about is rolling their own off usually by writing some crappy JavaScript instead of paying a SAS to do that for them but real men roll their own off entirely in postgress and that's possible when you combine a couple of extensions like PG crypto crypto and PG Json web token like if we have a table with a username and password we can use crypto to Hash the password and also generate Assa that ensures that when our database gets hacked the attacker won't have access to the plain text password and now to verify a user's login credentials we can write a simple query that matches the username to the hashed password with the Crypt function but the other thing we'll need is a way to validate user sessions on the server and one way to do that is with Json web tokens and PG JWT makes it really easy to cryptographically sign a token on the server and now that we have that we can Implement roow level security where the end user can only read and write data that's actually owned by their username this is a built-in feature in postgress where we create policies that Define rules about how our data can be accessed and in this case we'll verify the current user's token before executing any queries and that means selecting everything from the horse's table will only give us the hes owned by that user at this point we have a pretty complex application and we should start collecting some analytics data instead of Google analytics or another paid SAS an option you'll want to check out is PG moon cake basically it turns postgress into a Time series database and it's extremely fast and efficient because it adds support for column store tables with duck DB execution and all this data can be dropped into a cloud storage bucket and or visualized with other open source tools like grafana that's cool and all but we'll never actually get any analytics data if we don't make our data available on the internet to achieve that you might think you need to build a restful API with some programming language from scratch but another option is post rest which automatically turns your database into a uccessful API after you get it set up you'll be able to go into the browser then navigate to Local Host followed by a table name and it will automatically query your postgress data and return it in Json format on top of that you can do all kinds of other stuff like filtering pagination authentication and so on and now the final step to build a true full stack application is to store some HTML CSS and JavaScript in the database in fact there are even some crazies out there getting react server components to wrun in post grass and you really can't get your data any closer to the UI than that congratulations you're now officially a certified postgress Rison big shout out to Neon for reviewing and sponsoring this video and although they told me they don't approve of all the crazy stuff I showed you in this video I'm just going to go ahead and upload it anyway thanks for watching and I will see you in the next one

Original Description

Sign up for Neon and create up to 10 Postgres databases for free https://fyi.neon.tech/fireship Learn 10 unusual ways to use PostgreSQL to build a fullstack applications from scratch and harness the full power of this awesome relational database. #programming #database #webdevelopment 💬 Chat with Me on Discord https://discord.gg/fireship 🔗 Resources Postgres in 100 Seconds https://youtu.be/n2Fluyr3lbc SQL Tutorial https://youtu.be/Cz3WcZLRaWc 📚 Chapters 🔥 Get More Content - Upgrade to PRO Upgrade at https://fireship.io/pro Use code YT25 for 25% off PRO access 🎨 My Editor Settings - Atom One Dark - vscode-icons - Fira Code Font 🔖 Topics Covered - Cool things you can do with PostgreSQL - SQL tips - How to build a fullstack app with Postgres - Advanced database tips
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Fireship · Fireship · 0 of 60

← Previous Next →
1 Angular 4 Development and Production Environments with Firebase
Angular 4 Development and Production Environments with Firebase
Fireship
2 OAuth with Angular and Firebase Tutorial
OAuth with Angular and Firebase Tutorial
Fireship
3 Anonymous Authentication with Angular and Firebase - Lazy Registration
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
4 Angular Router Guards for Firebase Users
Angular Router Guards for Firebase Users
Fireship
5 Angular Firebase CRUD App with NoSQL Database Tutorial
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
6 Upload Files from Angular to Firebase Storage
Upload Files from Angular to Firebase Storage
Fireship
7 How to Deploy an Angular App to Firebase Hosting
How to Deploy an Angular App to Firebase Hosting
Fireship
8 Sharing Data between Components in Angular
Sharing Data between Components in Angular
Fireship
9 Loading Spinners for Asynchronous Firebase Data
Loading Spinners for Asynchronous Firebase Data
Fireship
10 Angular 4 Transactional Email with Google Firebase Cloud Functions
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
11 Firebase Database Rules Tutorial
Firebase Database Rules Tutorial
Fireship
12 Autocomplete Search with Angular4 and Firebase
Autocomplete Search with Angular4 and Firebase
Fireship
13 Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
14 Angular Drag-and-Drop File Uploads to Firebase Storage
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
15 Text Translation with Firebase Cloud Functions onWrite and Angular 4
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
16 Custom Usernames with Firebase Authentication
Custom Usernames with Firebase Authentication
Fireship
17 Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
18 Simple Pagination with Firebase and Angular 4
Simple Pagination with Firebase and Angular 4
Fireship
19 How to Connect Firebase Users to their Data - 3 Methods
How to Connect Firebase Users to their Data - 3 Methods
Fireship
20 Add Toast Message Notifications to your Angular App
Add Toast Message Notifications to your Angular App
Fireship
21 Facebook-Inspired Reactions System with Angular and Firebase
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
22 Learn NgModule in Angular with Examples
Learn NgModule in Angular with Examples
Fireship
23 Lazy Loading Components in Angular 4
Lazy Loading Components in Angular 4
Fireship
24 Stripe Checkout Payments with Angular and Firebase - Part 1
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
25 Process Stripe Payments with Firebase Cloud Functions - Part 2
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
26 Selling Digital Content in Angular with Stripe Payments - Part 3
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
27 Angular 4 Full Text Search with Algolia - Part 1
Angular 4 Full Text Search with Algolia - Part 1
Fireship
28 Algolia with Firebase Cloud Functions - Part 2
Algolia with Firebase Cloud Functions - Part 2
Fireship
29 Firebase Phone Authentication in Angular 4
Firebase Phone Authentication in Angular 4
Fireship
30 Top 7 RxJS Concepts for Angular Developers
Top 7 RxJS Concepts for Angular Developers
Fireship
31 Learn Angular Animations with 5 Examples
Learn Angular Animations with 5 Examples
Fireship
32 Advanced Firebase Data Filtering (Multi-Property)
Advanced Firebase Data Filtering (Multi-Property)
Fireship
33 Realtime Maps with Mapbox + Firebase + Angular
Realtime Maps with Mapbox + Firebase + Angular
Fireship
34 Angular Reactive Forms with Firebase Database Backend
Angular Reactive Forms with Firebase Database Backend
Fireship
35 Send Push Notifications in Angular with Firebase Cloud Messaging
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
36 Top 7 Ways to Debug Angular 4 Apps
Top 7 Ways to Debug Angular 4 Apps
Fireship
37 Infinite Scroll with Angular and Firebase
Infinite Scroll with Angular and Firebase
Fireship
38 Use TypeScript with Firebase Cloud Functions
Use TypeScript with Firebase Cloud Functions
Fireship
39 Realtime Graphs and Charts with Plotly and Firebase
Realtime Graphs and Charts with Plotly and Firebase
Fireship
40 Role-Based User Permissions in Firebase
Role-Based User Permissions in Firebase
Fireship
41 User Presence System in Realtime - Online, Offline, Away
User Presence System in Realtime - Online, Offline, Away
Fireship
42 Location-based Queries with GeoFire and Angular Google Maps
Location-based Queries with GeoFire and Angular Google Maps
Fireship
43 Angular ngrx Redux Quick Start Tutorial
Angular ngrx Redux Quick Start Tutorial
Fireship
44 Angular Ngrx Effects with Firebase Database
Angular Ngrx Effects with Firebase Database
Fireship
45 Progressive Web Apps with Angular
Progressive Web Apps with Angular
Fireship
46 Angular Ngrx with Firebase Google OAuth User Authentication
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
47 RxJS Quick Start with Practical Examples
RxJS Quick Start with Practical Examples
Fireship
48 Send SMS Text Messages with Twilio and Firebase
Send SMS Text Messages with Twilio and Firebase
Fireship
49 Firebase Database Performance Profiling
Firebase Database Performance Profiling
Fireship
50 Native Desktop Apps with Angular and Electron
Native Desktop Apps with Angular and Electron
Fireship
51 Subscription Payments with Stripe, Angular, and Firebase
Subscription Payments with Stripe, Angular, and Firebase
Fireship
52 Firestore with AngularFire5 Quick Start Tutorial
Firestore with AngularFire5 Quick Start Tutorial
Fireship
53 Angular HTTP Client Quick Start Tutorial
Angular HTTP Client Quick Start Tutorial
Fireship
54 Google Sign-In with Firestore Custom User Data
Google Sign-In with Firestore Custom User Data
Fireship
55 Star Review System from Scratch with Firestore + Angular
Star Review System from Scratch with Firestore + Angular
Fireship
56 Angular Chatbot with Dialogflow (API.ai)
Angular Chatbot with Dialogflow (API.ai)
Fireship
57 Learn @ngrx/entity and Feature Modules
Learn @ngrx/entity and Feature Modules
Fireship
58 Infinite Scroll Pagination with Firestore
Infinite Scroll Pagination with Firestore
Fireship
59 Faster Firestore via Data Aggregation
Faster Firestore via Data Aggregation
Fireship
60 Contentful - CMS for Angular Progressive Web Apps
Contentful - CMS for Angular Progressive Web Apps
Fireship

This video teaches how to use PostgreSQL to build full-stack applications from scratch, leveraging its advanced features and ecosystem of extensions. It showcases 10 unusual ways to use PostgreSQL, including using it as a time series database, implementing row-level security, and automatically turning the database into a RESTful API. By watching this video, viewers can learn how to harness the full power of PostgreSQL and replace multiple tools in their tech stack.

Key Takeaways
  1. Install PG Cron extension for scheduled SQL statements
  2. Use an unlogged table as a cache to prevent logging and improve performance
  3. Enable shared buffer to store data in RAM and use autovacuum to avoid bloat
  4. Use PG Vector extension for vector data type and nearest neighbors queries
  5. Load data set and vectorize it with PGAI extension
  6. Hash passwords with crypto
  7. Generate and verify JSON Web Tokens
  8. Implement row-level security with policies
  9. Collect analytics data with PG Mooncake
  10. Make data available on the internet with Post Rest
💡 PostgreSQL's advanced features and ecosystem of extensions make it a powerful tool for building full-stack applications from scratch, allowing developers to replace multiple tools in their tech stack and streamline their development process.

Related Reads

📰
Python Excel Automation: Create, Edit, and Format Text Boxes
Automate Excel tasks using Python to create, edit, and format text boxes in spreadsheets
Medium · Programming
📰
From Spreadsheets to Spark: Why Traditional Analytics Tools Reach Their Limits
Learn why traditional analytics tools like spreadsheets reach their limits and how to transition to more scalable solutions like Spark
Medium · Data Science
📰
Skill Verification for Data Roles: What Employers Should Know
Employers can verify data skills through practical assessments to ensure candidates can apply their knowledge in real-world scenarios, making hiring more effective
Dev.to AI
📰
The Data Engineering Skills Matrix AI Just Broke!
Discover how AI is changing data engineering skills and what it means for your team's SQL expertise
Medium · AI
Up next
This could be the most perfect data frontend
Matt Williams
Watch →