7+ million Postgres tables | Kailash Nadh | IndiaFOSS 2024 | FOSS United

Поделиться
HTML-код
  • Опубликовано: 6 янв 2025

Комментарии •

  • @SDAravind
    @SDAravind Месяц назад +8

    Thank you India FOSS for bringing talks from India product companies.

  • @royimon
    @royimon Месяц назад +23

    This is such a smart hack to be honest. This is one of those hacks id say which on paper sounds pretty crazy , but in practice actually ends up being really efficient. Makes you fathom how efficient postgres really is!

  • @jawakar8266
    @jawakar8266 19 дней назад +1

    Want more insightful tech talks like this!

  • @hirakdas4212
    @hirakdas4212 Месяц назад +2

    Really interesting hack! Thanks for sharing the tips. :)

  • @shravandhar6169
    @shravandhar6169 Месяц назад +5

    Great talk.
    Wonder if partition could have been done instead of creating dynamic tables since partition will internally create table(s) anyway but would be more managable.

    • @shabbirmurtaza6245
      @shabbirmurtaza6245 21 день назад

      Partitions will essentially be the same thing in this case.
      7 million tables sounds a lot cooler i guess 😜

  • @adarshshete7987
    @adarshshete7987 29 дней назад

    That was the coolest and smartest talk I have heard, Thank you Zerodha for opening up this hack as a service, we might consider using this in our company.

  • @davepoojan
    @davepoojan 22 дня назад

    Well explained sir!👍

  • @jeffamzn
    @jeffamzn 22 дня назад

    very interesting hack, really shows off the power of postgres

  • @ganeshbabu8263
    @ganeshbabu8263 Месяц назад +1

    Mind Blowingg!

  • @theSeniorSDE
    @theSeniorSDE 29 дней назад

    This is awesome ❤

  • @siya.abc123
    @siya.abc123 Месяц назад +48

    7 million TABLES, not rows? Yooooo

  • @mageshp4489
    @mageshp4489 19 дней назад

    It's really interesting

  • @saurabhprasad2295
    @saurabhprasad2295 29 дней назад +21

    I can't figure out how did DungBeetle, improve query time for generating reports. Like still the query is executed on huge base table and you are storing the results in a new table in results DB. Your query output is not instant, it still takes time as it did earlier, so what's the point of having 7M tables generated daily?

    • @sajjadhussain6149
      @sajjadhussain6149 29 дней назад +3

      Yes same is the point I was thinking about...but I think their perspective is make the application free from the overhead or what...I m still confused 😂

    • @maharshi4614
      @maharshi4614 29 дней назад +4

      I think further querying like sort filter etc will be faster on a dedicated table. Also results database can be designed for performance or querying, while base database has different design considerations.

    • @VishalSanghai
      @VishalSanghai 29 дней назад +8

      The problem being solved is not making individual queries faster. But to make the system resilient. Say on a busy day 10x reporting generating traffic comes, existing system will choke as 10x time those large queries will run. But through the async querying the client 'may' get delayed response, but is guaranteed to get one at some point.

    • @Vangaredddy
      @Vangaredddy 29 дней назад

      Listen it didn't down the main server with more request and app is not communicating directly with large slow database

    • @yagamilight120
      @yagamilight120 28 дней назад +1

      the idea isn't to optimize query time,idea is to decrease DB locking AND create a single abstraction layer which is decoupled from the app which can be scaled separately AND allow faster caching with further manipulation and aggregation.
      This is breaking like every single fundamental of DBMS and computer science in general but is a phenomenal example of product centered engineering lmao

  • @pranjalagnihotri6072
    @pranjalagnihotri6072 27 дней назад

    Super interesting talk was completely hooked to it for 20 minutes. Just one thing did you guys explored the approach of storing everything in 1 table, want to know the reason of coming with the idea of storing in a fresh table per use

  • @snehil32
    @snehil32 3 дня назад

    You can also used dungbeetle with s3 instead of postgres

  • @narasimhanmb4703
    @narasimhanmb4703 18 дней назад

    Few questions (I am a data engineer learning system design, so please be considerate if my questions are naive):
    1. 7+ million tables with 1TB of data doesn't seem huge. It's like ~140KB per table or per user report. I was actually shocked with the title (seems like a clickbait :D)
    2. But why can't we just use Kafka + stream-processing engine as that middleware. It still helps scale APP and DB independently. And sending messages to Kafka could be avro/protobuf which are more efficient than an API (mostly, JSON?)
    3. If I understand correctly, the results DB of postgres is simply a cached person data for quick access throughout the day instead of querying the huge DB again and again! Kinda materalized view in data engineering terms. AM I correct here?

  • @tejsinghranaofficial
    @tejsinghranaofficial 28 дней назад

    This one is interesting 😮😮

  • @omjogani7856
    @omjogani7856 Месяц назад

    Very well explained!

  • @keenzeen
    @keenzeen 29 дней назад +3

    This is what I understood. Please, tell me if my understanding is wrong. And why not Redis in this place?
    Imagine you have a bunch of information stored in a really big database. When someone wants to get some specific information from that database, it can sometimes take a long time to find it and give it to them.
    That's where this middleware comes in. It acts like a middleman between the person asking for the information and the big database.
    Here's how it works:
    1. The middleware has some pre-made "tasks" - these are like common questions people might ask, and the middleware already knows how to find the answers for those questions in the big database.
    2. When someone asks the middleware a question, it creates a "job" to go find the answer. This job runs in the background, looking up the information in the big database.
    3. While the job is running, the middleware stores the results in a separate, faster database. This way, the next time someone asks the same question, the middleware can just pull the answer from the fast database instead of having to search the big one again.
    4. When the person asks for the information, the middleware can give them the answer from the fast database right away, without having to wait for the big database to respond.
    The reason this middleware is useful is that the big database can be really slow, especially if lots of people are asking questions at the same time. By caching the answers in a faster database, the middleware can give people the information they need much more quickly.
    It's kind of like having a helper that knows where all the important stuff is stored, so they can grab it for you fast, instead of you having to search through everything yourself every time.

    • @vancedshitt6177
      @vancedshitt6177 28 дней назад

      abe bodam 🤣

    • @keenzeen
      @keenzeen 27 дней назад

      @@vancedshitt6177 😂that’s why i wrote my understanding. Please help me . I would appreciate it

    • @vancedshitt6177
      @vancedshitt6177 25 дней назад

      @@keenzeen it's simple, write once read a couple times. Not 1000s or 100_000 times. Just chasing for "flashy tech" and burning money for the sake of looking cool or boasting around has no meaning. Think about the cost of using in-memory caches
      and having a disk attached for backup with in-memory caches 🤦‍♂ is more idiotic in terms of cost - for them
      A bit off-topic:
      In most rdbms cost of deleting data is fragmentation (though they went a step ahead to replace the ebs volume to eliminate this limitation is even better instead of deleting tables/data). Vertical sharding has quirks related to query performances.
      Having tables is a simple solution that is supporting their business.
      There is no one size that fits all. Team should do what makes sense based on their collective goal.

  • @RamaM9520
    @RamaM9520 Месяц назад +5

    Great insight, I got a few doubts watching this video :
    1) Is it only one ec2 instance for dungbeetle ? Shouldn't we be having instances in multiple regions to ensure high availability?
    2)And in the rare case where a query is made when the instance is rebooting, do you have a retry mechanism there ?

    • @Goku-xm1gq
      @Goku-xm1gq 29 дней назад +5

      that's why zerodha lags, imagine having one instance for postgres db 128gb , 64vcpu

    • @HaimBenLulu
      @HaimBenLulu 29 дней назад

      Why not dropping a parquet or CSV to S3? Isn’t that cheaper than EC2?

    • @maheshwarang4000
      @maheshwarang4000 27 дней назад

      Instance reboots at night, so it’s usually down then. Makes sense since hardly anyone uses it at that time and it doesn’t affect business. Smart move

  • @mysterious6057
    @mysterious6057 23 дня назад

    Amazing. It is good to see that Zerodha started contributing to FOSS.

    • @FakeDumbDummy
      @FakeDumbDummy 23 дня назад +1

      started to contribute?
      they were always inclined towards foss, especially Kailash, they do have few decent tools open source which they developed for their internal use allready

    • @mysterious6057
      @mysterious6057 23 дня назад

      @@FakeDumbDummy I know that but, I am FOSS fund by Zerodha

  • @harjassgambhir
    @harjassgambhir 29 дней назад +1

    nice, interesting way to remove bottleneck from the base table

  • @prayushgiri6515
    @prayushgiri6515 26 дней назад +2

    An interviewer from tcs said “postgreSQL is only used for small databases 🤡”
    Happened to me in a real interview and I could only hold back my laughter 😂

    • @prashanthb6521
      @prashanthb6521 25 дней назад +1

      Postgres is good for large DBs but when it comes to performance like HPC situations, there are certainly better options. Postgres is too slow, especially for the scale at which Zerodha operates.

  • @rajkumardubey5486
    @rajkumardubey5486 26 дней назад

    Ok so here results db is like it is storing all the responses it getting for large db and storing as result in results db for serving the results to client so flow goes like
    Client request -> server which async queue which store the request then query data from large db in asynchronous manner -> then store response as data in results db for serving
    So dungbeetle using like local secodary indexing method for finding the users queried id with results which is store in results DB

  • @m4ni5h
    @m4ni5h 24 дня назад +1

    We have been using Temp/Ephemeral table for Analytics Reports since years. Its just that it does not have a 7+ million figure. Its not a hack, its design. It just sounds cool but pretty generic.

  • @johhanisburg
    @johhanisburg 25 дней назад

    Considering your queries are pre-determined, have you considered an IVM system like Materialize/Feldera and what would be the challenges?

  • @bharathau8085
    @bharathau8085 Месяц назад +1

    Thank you, Kailash Nadh, for such an insightful talk at IndiaFOSS 2024! The way you tackled the challenges of managing over 7 million Postgres tables and scalable report generation was truly impressive. The introduction of DungBeetle and the concept of independent middleware for handling large queries were game-changers. Your practical approach and innovative solutions are inspiring. Looking forward to exploring more in this space and implementing these ideas!

  • @drasticfred
    @drasticfred 25 дней назад

    It seems the financial institution has a wrong partitioning / sharding architecture for their use case. Their approach bound to create data inconsistencies too, i wonder, how do they check consistency of final data, returned to the customers? Institution needs an event processing pipeline for customer reports, after financial transactions are cleared, finalized and sealed.

  • @dgdev69
    @dgdev69 Месяц назад

    This is why zerodha is so cool. Like many people making product dont care about performance.

  • @tempregex8520
    @tempregex8520 28 дней назад

    Great idea, and talk beautifully done but, what happens to stale tables? meaning when we have stale records in a table we could leverage ttl or some delete records approach. Isn't there a use case to "delete old records" tables in this case?What happens when say a user deletes their zerodha account? does ALL their records(and tables created due to their queries) get deleted too?

  • @paddor
    @paddor 25 дней назад

    Very interesting. I have a few questions:
    If you wipe all report results every night, why even store them? Is the same report generated multiple times a day?
    Is using pg_hash/JSONB colums not an option because you also need to support other DBMS? This would still allow saving all results into one table, and create a VIEW for each result, so that apps don't have to use WHERE.

  • @Programmers_1998
    @Programmers_1998 24 дня назад

    That is crazy

  • @SwapnilNakate7
    @SwapnilNakate7 Месяц назад

    incredible

  • @SouKube
    @SouKube 8 часов назад

    reading through these comments i too felt if this is such a big of a thing, or hack or abuse as its called here. another thing, dung-beetle is already used for a cross-browser tool developed way back. i felt a bit of bad taste, duplicating the name for something very different or rather not checking for uniqueness. but at the same time, appreciate the execution/implementation however small the idea is. i would suggest or it would be interesting adding some ML/AI capability to predict what reports are in demand and making it a generic proxy to the reports module of any web app.

  • @ossamarafique3003
    @ossamarafique3003 28 дней назад +1

    Interesting talk, But As they delete the data every day, if I want to look at the report that I generated 1 day ago, I'll have to go through the process again?

    • @maheshwarang4000
      @maheshwarang4000 27 дней назад

      thats how most of the inmemory cache works with TTL

    • @ossamarafique3003
      @ossamarafique3003 27 дней назад

      @@maheshwarang4000 I understand how cache with TTL works, but if a report takes a long time to generate-for example, on peak days, assuming it could take up to 5 minutes. When users who return later on website or the app (more likely to happen with more wait times) have to go through the same process again? How is this handled in terms of user experience?

    • @spacepacehut3265
      @spacepacehut3265 25 дней назад

      ​@@ossamarafique3003yes that's right the user has to wait again. And this hack is basically for reducing main DB load and just handling the million requests through another layer which is dungbeetle

  • @_sairam
    @_sairam Месяц назад +3

    Would s3 with parquet format work? Assuming 300MB on average

    • @aakashvenkat2733
      @aakashvenkat2733 Месяц назад

      Too costly

    • @_sairam
      @_sairam Месяц назад

      ​@@aakashvenkat2733 yeah. possibly because of s3 retreival costs. storage is only for day as you are dropping the db. Let me try to build a calculation and get back.
      postgres is definitely works for the job as the main operation is around sorting and pagination once the data is retrieved. The new postgres is acting as a cache.

    • @aakashvenkat2733
      @aakashvenkat2733 Месяц назад +1

      @@_sairam yeah, but idk why they didn’t go with any NoSQL db since they can store unstructured data as json easily. I used a similar architecture for cache in my previous organisation.

    • @_sairam
      @_sairam Месяц назад

      @ json is too verbose. If someone wants to optimise, they can do so with inherited tables etc, but that was not the goal I presume. It’s about that solutions can be implemented with very less code to address business problems

  • @rohithjanardhan4970
    @rohithjanardhan4970 Месяц назад

    Glad to hear from a GOAT like Kailash. Why was the choice made to use postgres instead of a distributed caching layer like Redis/memcache?

    • @kannanmelathil
      @kannanmelathil Месяц назад

      Yeah I am also thinking the same 🤔

    • @nilanjanchakraborty2694
      @nilanjanchakraborty2694 Месяц назад

      Can we run sql query in redis? Because in this data will not same all users. @rohithjanardhan4970

    • @sharthakghosh970
      @sharthakghosh970 Месяц назад +2

      Cache is extremely expensive. Also the problem with Redis is you cannot simply just store large objects in it. Out of the blue you may see tail latencies spiraling out of control. Pretty common problem with Redis. Infra teams managing Redis at large companies often advise dev teams to tread cautiously.

    • @DesuTechHub
      @DesuTechHub Месяц назад

      redis is optimised for key based lookup... observe the select query where user id along with date range which is not static key.. So it generally need a relational db or flat file processed approach

  • @tesla1772
    @tesla1772 Месяц назад

    Dungbeetle service will need access to all the databases of different services. How will a single sql query manage to connect bring data from different databases and create record from it?

    • @dn5426
      @dn5426 Месяц назад +1

      They probably don't have a requirement for reports which utilizes multiple data sources.
      If they did, I think Clickhouse would be a pragmatic way to do it. It lets you create virtual tables for bunch of remote databases like postgres, mongo, mysql etc.

  • @rainerwahnsinn2150
    @rainerwahnsinn2150 29 дней назад

    That sounds like a job for sqlite - one file per report?

  • @aakashvenkat2733
    @aakashvenkat2733 Месяц назад +2

    Why wasn’t a noSQL DB considered? It can hold json as documents and each user can be one document. We don’t even need to follow a structure since each document can have different fields altogether

    • @TVmail-dt1ey
      @TVmail-dt1ey 29 дней назад

      They have to analyticals and more over migrations are hard

    • @akrammohammed3581
      @akrammohammed3581 29 дней назад

      The data majorly related to other data that's why they use sql

    • @Vikasptl07
      @Vikasptl07 29 дней назад

      ​@@akrammohammed3581 can they not store those query results in no SQL considering results are mostly aggregated? That way you don't have do hack of creating throw away tables.. and when same user request the same report again you don't even have to fire those queries which they will be doing in current approach since they just remove them daily.

    • @aakashvenkat2733
      @aakashvenkat2733 29 дней назад

      @@akrammohammed3581 as per kailash himself, they have written a service which can join data from different databases together

    • @gokukakarot6323
      @gokukakarot6323 29 дней назад +1

      Most of their queries would be range queries and join queeies. and he didn't say write is the problem.
      The choice comes down to:
      - CA(p)
      - Consistency/Isolation level
      - Nature of data
      - Read Write throughput
      - Available expertise of the team
      Figma vs Discord database saga is an example.

  • @Hybrowlabs_Technologies
    @Hybrowlabs_Technologies 28 дней назад

    But why not use Redis Cache with Redis Search ?

    • @arunbabu6524
      @arunbabu6524 20 дней назад

      2 TB in cache memory , that is RAM ?. Redis / cache DBs are for low latency operations. It’s an Async operation which requires huge storage space .

  • @parikannappan1580
    @parikannappan1580 29 дней назад +1

    DuckDB could also be tried

    • @prashanthb6521
      @prashanthb6521 25 дней назад

      DuckDB with Apache Arrow would work nice here.

  • @Dibyendu-dev
    @Dibyendu-dev 29 дней назад

    Chai aur code lands me here❤❤❤

  • @paddor
    @paddor 25 дней назад

    What you're describing in this whole talk, isn't that just MATERIALIZED VIEWS? (assuming the reports are generated from other data from the same DB)

  • @Clma333
    @Clma333 27 дней назад

    This was such an insightful video! . It reminded me of a video series I recently made on S3 buckets, where I dive deeper into core concept of S3 like replication versioning,storage classes. If anyone’s interested, feel free to check it out - I’d love to hear your thoughts!

  • @interesting_stuffs
    @interesting_stuffs 28 дней назад

    A table for every user?

  • @tusshar2000
    @tusshar2000 29 дней назад

    Why not use redis cache?

    • @arunbabu6524
      @arunbabu6524 20 дней назад

      2 TB in cache memory , that is RAM ?. Redis / cache DBs are for low latency operations. It’s an Async operation which requires huge storage space .

  • @prashanthb6521
    @prashanthb6521 Месяц назад +1

    I dont see myself as an expert but in my experience its better to switch to another DB other than Postgres, when performance matters. Postgres is for stability & Integrity, not for caching. Questdb or Clickhouse would have been better.

    • @vancedshitt6177
      @vancedshitt6177 28 дней назад +2

      you certainly lack knowledge.

    • @paddor
      @paddor 25 дней назад

      LOL

    • @prashanthb6521
      @prashanthb6521 25 дней назад

      @@vancedshitt6177 abe bodam your shitt6177 comment doesnt mean anything if you dont elaborate what is wrong in my approach.

    • @prashanthb6521
      @prashanthb6521 25 дней назад

      @@vancedshitt6177 I design & build HPC stuff, I have done sufficient benchmarking with postgres to make that comment. This design by Kailash is very poor. Maybe you should check back on your knowledge, maybe its too generic.

    • @prashanthb6521
      @prashanthb6521 25 дней назад

      @@paddor LOLWA

  • @human-011
    @human-011 29 дней назад +1

    Thats simply scaling materialized-views

  • @hemanthaugust7217
    @hemanthaugust7217 28 дней назад

    this sucks...that's why zerodha reports take longer and even the portal is quite slow.
    Why don't guys hire a good architect and yes, he/she will keep the systems simple..we don't have to overcomplicate systems..but this is plain dumb use of DB.
    Secondly, it's not a lot of data & users; hence, it's working fine for you.
    If you have a lot of records, your RAM will not be enough ; that's when you will have to shard it.

  • @HarisankarPS
    @HarisankarPS 29 дней назад

    The only true solution/take back in this video is the fact that they can delete/reset an empty DB by re-attaching and empty volume. Its more like a testament for amazon/cloud tools than Postgres.
    Funny that is a FOSS conference.

  • @anishmctavish8709
    @anishmctavish8709 29 дней назад

    13:02 and all Ive learned till now is that we have 100s of millions of lines of reports of financial... bhai kaise karna hai ye bhi bata de

  • @Vikasptl07
    @Vikasptl07 29 дней назад

    Felt Hacky and it works for now but question is how long this will be sustainable!!! considering solution is mostly focused on large number of "User reports" which may or may not have similar schemas it does makes sense to save results of query until request comes back. Other solution could be saving those sql results in No sql as documents and populate those reports.
    The way they shut off postgre every day remove disk and all.... Just for removing those tables.... we expect better things from you guys given you are no longer start up but largest stock broker of country that has growing Dmat user base.

  • @sudityashrivastav
    @sudityashrivastav Месяц назад +2

    If a company has 7 m which means 70 lakh tables you are doing something wrong

  • @imdnxt
    @imdnxt 24 дня назад

    This hack is hot garbage. These people don’t know how to properly use Postgres (and their tools and their time). Nobody should be taking notes from this presentation.

  • @axixur7353
    @axixur7353 29 дней назад +3

    7M tables..poor design without any doubt. Sorry.

    • @Goku-xm1gq
      @Goku-xm1gq 29 дней назад +1

      i think he meant records, no way they got 7m tables lmao

    • @Goku-xm1gq
      @Goku-xm1gq 29 дней назад +1

      oh wait holy shit, he is creating new table for each job id in resultsdb

    • @kyle7382
      @kyle7382 28 дней назад +2

      yeah the fact that postgres can handle 7million tables is impressive but I'm VERY skeptical that this was the best solution they could've used to solve the problem even if it happens to work for now.

    • @prashanthb6521
      @prashanthb6521 25 дней назад

      I too think this is a poor design, but from a overall architecture point of view, not about schema.

  • @badpotato
    @badpotato Месяц назад

    most basic presentation of all... stop indian companies from delivering presentatiom