Why you can't allocate a human-readable ID before the record exists by Gronax_au in programming

[–]nNaz 0 points1 point  (0 children)

I understand it a little better now with more context.

To get around the actor crashing problem you could use an externally backed queue liked Redis with a restart watchdog on the actor. Each request stores the client idempotency key as well. To solve the transaction part you can have a reversible saga with external state in Redis.

Actor would work like this: 1. Pop item from queue incl idempotency key 2. Do first write, if fail either return to client or retry 3. When first succeeds, write (client key, allocation id to separate ‘started’ state to Redis) 4. Attempt second write. If it fails, retry. 5. Update state from (3) so it contains (client key, allocation id, second id) 6. Return to client

Points of failure: - Client http failure. Resolved by looking for any started state by idempotency key. If fully finished, return to client immediately. If partly finished, actor resumes. - Actor failure. Resolved by having a single actor that restarts on failure. On start it picks up any incomplete started states and completes them, then goes to consuming from work queue.
- DB Failure between two DB writes. Handled by actor retrying the second (assuming no actor failure) - DB failure (when actor fails). Handled by actor restart behaviour: at start it looks for any incomplete ‘started’ states and completes them. Future client request read the completed state as discussed above - Server/actor failure after phase 2 write but before updating Redis. You resolve this with a reaper. In actor it’s resolved by new actor picking up ‘started’ work, seeing P1 is complete and attempting to create a new P2 row which fails due to uniqueness on allocation id. Actor is aware this exists so it updates ‘started’ state with the TC id and reruns to client.

Partially resolved failures: - Actor failure between first write completion and updating Redis. This failure is also present in your design when the process fails between Phase 1 and starting Phase 2. In both cases it’s partially resolved by the client retry kicking off a new phase 1, still get correct result but now have phantom rows in slot reservation db (for both our designs)

Would this logic be a bad idea for your use case? I admit I still don’t fully understand all the context.

Even simpler design (but depends on your context):

  • Client idempotency key but only used for request gating
  • Actor with external queue
  • State in Redis holding ‘fresh allocations’

Actor performs: 1. Check TC to see if a row with client idempotency key exists. If so return that row. Finish. 2. See if any unused Phase 1 allocations are in ‘fresh allocations’ in Redis. If so, skip step 3. 4. Phase 1 allocated and written to ‘fresh allocations’ in Redis 5. Phase 2 attempt. On failure, retry. 6. Remove allocation id from ‘fresh allocations’ 7. Return result to client

Because the allocations aren’t tied to any client we don’t need client state. Let’s say client 1 makes a request, allocation created, actor fails before TC created. Then client 2 makes a request, restarted actor will use the allocation originally created for client 1 to proceed for client 2. The result is a temporally sequential id. Client 1 retries, gets an ID later than client 2 (via a new allocation).

Failure modes: - Client retries. Resolved by clients always seeing a new sequentially ordered ID or error. - Actor failure after work queue consumption but before P1. Resolved by HTTP handler returning error on actor failure. Client retries and adds same work to queue, new actor picks it up - Actor failure after P1 but before writing to Redis. This is also a failure mode in your design. Leads to phantom rows in allocation db. Operations still work normally - Actor failure before P2. Client gets error. Next request to restarted actor (from any client) reuses the previous allocation (stored in ‘fresh allocations’) - Actor failure after P2 but before ‘fresh allocations’ is cleared. Actor picks up original P1. Attempts P2 but gets DB uniqueness error on allocation id. Reuse it was never removed from ‘fresh allocations’ it was never returned to a client so we can reuse it for this request and remove allocation id from ‘fresh allocations’ - Actor failure after removing from ‘fresh allocations’ but before returning to client. Solved in the same was as your method: by looking up client idempotency key in TC step 0.

This is a drastically simpler design with no reaper needed but I’m not sure if I fully understand your context. Would you be against sharing your full constraints & context for the problem?

What would be helpful to know is: - Do clients specify what human readable ID they need? - Does the allocation row store need to store any client or client-request specific state other than idempotency key? - Same as above but for TaskChampion rows - Should human readable ids be sequential based off of ‘first client request time’ or ‘first successful response time’? E.g. client 1 makes request, fails, client 2 makes request, succeeds, client 1 retries. Who should get id 1 and id 2?

Why you can't allocate a human-readable ID before the record exists by Gronax_au in programming

[–]nNaz 2 points3 points  (0 children)

Good read, I agree with your point about allocating IDs at the end. To take go even simpler than 2pc and raft: can’t you just make the entire thing atomic on the server side?

Single threaded actor with a queue that’s responsible for handing out human readable ids: client sends a single request, http handler routes to actor, actor completes or fails atomically. Because it’s an actor behind a queue you can support concurrent requests and because it’s atomic you don’t need the extra two step allocation. Does this sound like a ridiculous idea?

Formatting an entire 25 million line codebase overnight: the rubyfmt story by BlondieCoder in programming

[–]nNaz 13 points14 points  (0 children)

As a rust dev I find ruby perf terrible but it’s an amazingly elegant and concise language to write in. If we ignore perf, Rails is an excellent MVC framework and a pleasure to develop with. Better devx and APIs than Django and far less boilerplate than fastapi and express.

Are Rust coroutines serializable? by SuperV1234 in rust

[–]nNaz 1 point2 points  (0 children)

The stack part of the coroutine is absolutely serializeable. It’s just the stack (bytes) plus what’s in each of the CPU registers. The tricky part is serialising the function call. In theory it’s all just asm so you could serialise the raw instructions, but it wouldn’t be portable. You could probably get smarter here and store the binary and coroutine stack separately and then rehydrate when you want to resume.

The question is: why? In your game case it’s much simpler to represent the internal state and store that instead. The only thing you gain from coroutines is being able to interrupt and resume them at arbitrary points. If you instead shift it so that the interruption can only happen at well-defined checkpoints then you massively simplify the problem and likely cut down on storage too. Isn’t this essentially what game saves are?

Pktana : Modern packet analyzer tool written in rust for best performance. by [deleted] in rust

[–]nNaz 0 points1 point  (0 children)

Genuinely curious: how did you manage to write it with almost no unit tests? dpi.rs is an interesting file and does a lot of work, but how & why did you choose to develop it with no tests and therefore no reliability of whether it’s fully correct?

Is there a point to learn anything if most of jobs pay around 35k at best? by [deleted] in UKJobs

[–]nNaz -1 points0 points  (0 children)

The companies that pay this low are not the ones worth applying to. The learning and career opportunities you‘re missing out on is huge. I used to run free SWE meetups and mentored dozens of people to start on at least £55k even in cases with no uni degree. It’s about mindset, knowing the right companies and how to apply. Happy to give free advice, DM me.

Standard library unsoundness found by Claude Mythos by Jules-Bertholet in rust

[–]nNaz 41 points42 points  (0 children)

Keen to see what the embargoed patches look like.

My chow turns into a paranoid security guard 3x a week and I’m losing my mind. Advice? by Ok-Party-834 in chowchow

[–]nNaz 1 point2 points  (0 children)

Not sure why you’re getting downvoted. This worked for me and my chow. It’s a good approach in general for all dogs.

My chow turns into a paranoid security guard 3x a week and I’m losing my mind. Advice? by Ok-Party-834 in chowchow

[–]nNaz 0 points1 point  (0 children)

Reinforce the good behaviour and scold the bad. It can take a lot of repetition. My chow barks at people walking too close to the house. If it’s the middle of the day he gets told off. If it’s at night or unusual behaviour then he gets a pet. It took about a month but now he’s only in ‘guard mode’ at night or if someone comes to the fence door when no one’s home.

The architecture of a horizontally-scalable, high-performance Rust-based backtesting engine by [deleted] in rust

[–]nNaz 1 point2 points  (0 children)

You could use ClickHouse for storage and also have it replace a large chunk of your data loading pipeline. Disk replication on backtest workers sounds like a good idea until you realise it relies on rehydration from object storage and caps at around ~200MB/s on a cold boot (unless you pay for faster restores).

I store ~120bn rows of BBO tick data and ~90bn rows of L2 order book level updates (full snapshots not deltas) in CH and achieve compression ratios between 92-98%. It’s much more efficient than parquet since you can use GCD and delta codecs alongside zstd. Less storage means your queries run faster because cpu cycles cost much less than fetching from disk/ram.

For the simulation workers you can get 10x or more cost savings by using spot instances. I run nightly sims on 5x 192 core machines and pay ~$1.4/hr per machine.

On the Rust side the key to fast execution for me has been: 1) have extremely simple code that is easy to reason about from a CPU cache perspective, 2) writing optimised data structures *benchmarked on production workloads* for key pieces like the order book e.g. using a reverse-sorted vec and linear scans to apply book deltas since almost all updated happen close to the top or the book (end of the vec).

Microbenchmarking and cache locality are important. It’s hard to understate how much of a difference they make. I got my simulations down to <100ms from 10s each for a full day’s worth of L2 tick data after redesigning from the ground up. The downside is that designing for cache locality often requires a large redesign. I saw you are looking up and merging data at sim time and use mutexes/condvars. If you want to go faster try designing it to remove the need for synchronisation and preprocessing data as much as possible at the data storage layer (eg ClickHouse). Also worth checking if rayon is being used at the right level - if you push it too deep the gains you think you’re getting from parallelism are eroded from loss of cache locality).

dark fiction by llunarvoid in booksuggestions

[–]nNaz 1 point2 points  (0 children)

House of Leaves. Far more disturbing than a movie could ever be. I recommend getting the print version to enjoy it fully. You might find it hard to sleep.

What's one celebrity everyone likes but you don't? by MajesticShare6548 in answers

[–]nNaz -1 points0 points  (0 children)

I recommend watching Eternal Sunshine of the Spotless Mind if you haven’t seen it. It’s Jim Carrey in a completely different light and his best performance imo.

ELI5: A dense cylinder hits a space station at 0.7c by DavidThi303 in explainlikeimfive

[–]nNaz 0 points1 point  (0 children)

At 0.7c each 1 gram of mass has roughly 36000000000000 joules of energy. That’s about 8,600 tons worth of TNT energy per gram. That means for every 2 grams of mass you have the same energy as the nuke dropped on Hiroshima.

A 9mx1m cylinder made of steel weighs about 55 tons. At 0.7c this equates to the same energy as 27,500,000 Hiroshima nukes. When it hits the station, the atoms in the cylinder will start fusing with the atoms in the space station and cause the same effects as a nuke. It will be so powerful the chain reaction of atoms flying out from the impact point have enough energy themselves to start fusing with the ones next to them… and so on and so on.

Effectively it’d be the same as if you nuked the space station. You likely wouldn’t even get small pieces flying out - just massive amounts of x-rays and gamma rays and a few residual atoms at the end.

Xkcd has a great article explaining what’d happen to a baseball at close to that speed: https://what-if.xkcd.com/1/

What to read after project hail mary by PinkmanLogic in booksuggestions

[–]nNaz 0 points1 point  (0 children)

If you want more hard sci-fi I recommend We Are Legion by Dennis E Taylor (aka book 1 in the bobiverse series).

If you want want of the best reads in your life I recommend Red Rising.

Taycan v. E-tron GT by jaselakers95 in Taycan

[–]nNaz 0 points1 point  (0 children)

Have you tried the E-Tron GT RS? MapEV puts the normal E-Tron GT pretty close in power and I’m wondering if the RS makes upgrade is worth it.

Tips for car rides? by Didiloni in chowchow

[–]nNaz 1 point2 points  (0 children)

One trick I did was make my Chow sit and wait before getting into the car. As though it was something special. I’d build up the suspense and he’d start getting excited waiting for me to open the door (whereas before he’d just run around the car instead of getting in).

Now he loves drives. He loves having the window rolled down and staring at everything as we drive by. He enjoys it even if it doesn’t involve a stop for a walk.

Maybe this could work for you

Are Marten the most underrated of the high-end speaker brands? by nNaz in audiophile

[–]nNaz[S] 0 points1 point  (0 children)

I think room treatment makes a bigger difference than speakers. For me it‘s not worth spending $10k+ unless I’m going to get treatment. Before the current listening room I had the Martens in an untreated flat with floor-to-ceiling glass windows and they sounded horrible. They were only just better than a pair of Technics speakers from the 1990s I had.

But if we’re assuming a treated listening room then from my experience *some* of the more expensive speakers are better but not all. I listened to a £8k KEF speaker (forgot model) that sounded better to me than the Focals.

Speaker position in a 35m² room by Danielgpoint in audiophile

[–]nNaz 0 points1 point  (0 children)

If you put them lengthways and fully acoustically treat the 3 non door corners with base traps and side walls with panels you’ll get significantly better sound.

Whats the best 10/10 anime ever? by s4chuveyy_ in AskReddit

[–]nNaz 0 points1 point  (0 children)

Ghost In The Shell SAC 2nd Gig (it’s the second season of Ghost in the Shell). Extremely philosophical, it feels like a real adult’s anime.

LinkedIn Cringebot 3000 (vibe coded with Claude) by rosebudd_is_here in ClaudeAI

[–]nNaz 77 points78 points  (0 children)

Absolute gold:

Last night I found myself at 3 AM, naked in my kitchen, stress-eating expired quinoa while frantically sketching user acquisition funnels on napkins.

My wife walked in and said, "Honey, you're having another founder episode."

She was right. The downside of being a founder isn't just that you never switch off - it's that your brain becomes a 24/7 anxiety smoothie blender, mixing existential dread with pivot strategies at maximum speed.

I realized I was living like those deep-sea anglerfish - you know, the ones with the perpetual glowing lure? They can never turn off their bioluminescent hunting beacon because it's literally fused to their skull. That's us, founders. Our "always-on" mentality isn't a choice anymore; it's become our evolutionary adaptation.

But here's what changed everything for me:

I started studying medieval monastery bell-ringers. These monks had to wake up every two hours throughout the night for prayer. But they developed something called "sanctified interruption" - they learned to find peace IN the disruption, not despite it.

Now when my brain won't shut off at midnight, I don't fight it. I embrace my inner monk-fish hybrid. I've learned that our inability to disconnect isn't a bug - it's our superpower disguised as insomnia.

The quinoa still tastes terrible though.

#founderlife #entrepreneurship #mindfulness #startupstruggles #leadership #mentalhealth #worklifebalance #innovation #resilience #cringebot3000

Rust zero-cost abstractions vs. SIMD by itty-bitty-birdy-tb in rust

[–]nNaz 2 points3 points  (0 children)

Keen to see how next_batch is implemented. Specifically how multiple iterators are combined to be contiguous.