Another neat hack is to use Postgres as a quick & dirty replacement for Hadoop/MapReduce if you have a job that has big (100T+) input data but small (~1G) output data. A lot of common tasks fall into this category: generating aggregate statistics from large log files, searching Common Crawl for relevant webpages, identifying abusive users or transactions, etc. The architecture is to stick a list of your input shards…
If a worker fails or gets pre-empted, how does it retry anything? It's gone at that point, no? Sounds like you'd end up with a bunch of dangling shards orphaned in WORKING state. And now you need timeouts and health checks and something to coordinate all that.
System design hack: Postgres is a great pub/sub and job server
71–80 of 162 posts
Re: System design hack: Postgres is a great pub/sub and job server
#72Kinesis is based on DynamoDB... Key-value stores could do a lot of things theoretically.
Re: System design hack: Postgres is a great pub/sub and job server
#73Earlier quoted context omitted.
>> spin up a bunch of worker processes as EC2 spot instances that check for the next PENDING task Does that mean workers poll the database?
Yup, but they do so only once per shard (well, twice, once at the beginning and once at the end). If you've got a big job where each shard takes a few minutes to process and a hundred or so workers, the DB gets about 1 req/sec, which is well within the capabilities of Postgres.
Re: System design hack: Postgres is a great pub/sub and job server
#74Re: System design hack: Postgres is a great pub/sub and job server
#75Postgres generally has a fairly low maximum connections. If you're running your own servers, you can adjust this, but in the cloud you may not be able to. For example, Google CloudSQL maxes at 1000, Heroku at 500. At that point, people usually start looking at the connection pooling tools. Depending on how much work you need from the DB, connections pools can be a win. Anyone know how connection pooling works with li…
Can't say about listeners. But connection poolers introduced more problems than I cared to fix. So now I routinely use 3000 connections, and have 9000 set up for peaks. It eats a little more ram but it is more stable.
It also eats a lot more cpu cycles:
Re: System design hack: Postgres is a great pub/sub and job server
#76> It's rarely a mistake to start with Postgres and then switch out the most performance critical parts of your system when the time comes. This is pretty good advice in general.
Re: System design hack: Postgres is a great pub/sub and job server
#77Keep in mind that a notify performed when nobody is listening is lost. The workers need then to catch up.
This is where the Debezium connector for Postgres [1] comes in: it will retrieve change events from the TX log and push it to brokers such as Apache Kafka or Pulsar, or directly to your application. When not listening, any consumer will continue to read from where it left off before (applying "at least once" semantics). Disclaimer: I work on Debezium [1] https://debezium.io/documentation/reference/0.10/connectors/...
Could you please elaborate?
Re: System design hack: Postgres is a great pub/sub and job server
#78> It's rarely a mistake to start with Postgres and then switch out the most performance critical parts of your system when the time comes. This is pretty good advice in general.
Adding postgres there and there where it's clearly the wrong tool is a bad advice.
Re: System design hack: Postgres is a great pub/sub and job server
#79Used the "FOR UPDATE SKIP LOCKED LIMIT 1" trick to implement a job server in PG a few years ago for the first time. It's a great solution.
Why the “LIMIT 1”?
On my first go I was taking batches, on the reasoning that it optimized for query performance. It was a complete disaster and I quickly realized that I was engaging in premature optimization.
Batching is out, stream-processing is in. If you design your job table correctly, PG will perform very well as an advanced stream processor.
Re: System design hack: Postgres is a great pub/sub and job server
#80At the scale I operate at, I wouldn't consider this a viable option. What's the backpressure like on NOTIFY/LISTEN? (Docs mention a maximum backlog of 8GB on the message queue, is that configurable? Monitorable?) Tons of constant churn on a table means we have to worry about vacuuming right? Now I have to monitor that too to make sure it's keeping up. Not to mention all the usual operational issues with running relat…
hell, even its clustering system got a lot better!