frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Show HN: Onesinglecounter, a Globally Available Counter

https://onesinglecounter.com
3•v3lmx•7mo ago
Hey HN,

onesinglecounter is a single globally available counter with 2 buttons: one increments by 1, the other resets to 0. The website keeps track of the largest values attained in the last minute, hour, day, week, month, year, and all time.

This is a toy/experiment website to see how anonymous people will interact: one person is enough to keep the counter close to 0, so it's interesing to me to see how high the counter can get.

The backend is written in Go, and the frontend in Svelte (no kit), using shadcn for components. They communicate using a websocket that sends updates on the current value of the counter and the recorded best values per timeframe.

I started with a naive approach of storing all the connected clients in a global state, and going through all of them on each update (eg. someone clicks one one button). However, this approach quickly fell apart when the number of clients grows: number of clients * number of events per second was too much for the server to handle (this could be also because of other mistakes on my part, the early implementations were not optimal).

I then moved on to using a tick system, where the state is updated in real time from the clients to the server, but the server only update the client every tick. This drastically improved performance, and is not even noticeable on a low tick rate.

I also moved from using a mutex protected counter to an atomic value. The golang `sync/atomic` package provides an implementation for atomic operations on numbers, which allows for lock-free updates to the counter. This simplified the code, and there is no tradeoff that I could see in this particular case.

I researched other approaches around UDP and multicast, but UDP is not available natively in browsers, which is a shame as I could have streamed the updates with way less overhead.

I also learned about `sync.Cond`, which allows for synchronization between goroutines, which allowed a simple way to notify multiple goroutines when an event occurs, such as a tick update. I ended up using an implementation with channels that I found here while researching the subject (https://blogtitle.github.io/go-advanced-concurrency-patterns...), as this was more performant in my use case that using `sync.Cond` directly (from the limited testing I did, all else being equal, the `sync` package utilized 99% CPU, vs 75% for the channel implementation. There might be something else going on here, I did not really dig into this).

Another issue that seemed simple at first but wasn't straightforward was the best values per timeframe. I ended up using a golang cron library that schedules a job to run every timeframe to potentially reset the best values to the current value of the counter. This was the simplest way I found to get the values to reset not every timeframe, but at the beginning of each timeframe.

I am very interested in hearing opinions and suggestions on how you would have tackled some of the problems I encountered!

You can check out the website at https://onesinglecounter.com, and the source code is available at github.com/v3lmx/onesinglecounter.

Comments

Hackbraten•7mo ago
I just see a blank page?
v3lmx•7mo ago
Very sorry, I messed up my deployment... It should be up now

Was going to share my work

1•hiddenarchitect•1m ago•0 comments

Pitchfork: A devilishly good process manager for developers

https://pitchfork.jdx.dev/
1•ahamez•1m ago•0 comments

You Are Here

https://brooker.co.za/blog/2026/02/07/you-are-here.html
1•mltvc•6m ago•0 comments

Why social apps need to become proactive, not reactive

https://www.heyflare.app/blog/from-reactive-to-proactive-how-ai-agents-will-reshape-social-apps
1•JoanMDuarte•6m ago•1 comments

How patient are AI scrapers, anyway? – Random Thoughts

https://lars.ingebrigtsen.no/2026/02/07/how-patient-are-ai-scrapers-anyway/
1•samtrack2019•7m ago•0 comments

Vouch: A contributor trust management system

https://github.com/mitchellh/vouch
1•SchwKatze•7m ago•0 comments

I built a terminal monitoring app and custom firmware for a clock with Claude

https://duggan.ie/posts/i-built-a-terminal-monitoring-app-and-custom-firmware-for-a-desktop-clock...
1•duggan•8m ago•0 comments

Tiny C Compiler

https://bellard.org/tcc/
1•guerrilla•9m ago•0 comments

Y Combinator Founder Organizes 'March for Billionaires'

https://mlq.ai/news/ai-startup-founder-organizes-march-for-billionaires-protest-against-californi...
1•hidden80•10m ago•1 comments

Ask HN: Need feedback on the idea I'm working on

1•Yogender78•10m ago•0 comments

OpenClaw Addresses Security Risks

https://thebiggish.com/news/openclaw-s-security-flaws-expose-enterprise-risk-22-of-deployments-un...
1•vedantnair•11m ago•0 comments

Apple finalizes Gemini / Siri deal

https://www.engadget.com/ai/apple-reportedly-plans-to-reveal-its-gemini-powered-siri-in-february-...
1•vedantnair•11m ago•0 comments

Italy Railways Sabotaged

https://www.bbc.co.uk/news/articles/czr4rx04xjpo
3•vedantnair•12m ago•0 comments

Emacs-tramp-RPC: high-performance TRAMP back end using MsgPack-RPC

https://github.com/ArthurHeymans/emacs-tramp-rpc
1•fanf2•13m ago•0 comments

Nintendo Wii Themed Portfolio

https://akiraux.vercel.app/
1•s4074433•17m ago•1 comments

"There must be something like the opposite of suicide "

https://post.substack.com/p/there-must-be-something-like-the
1•rbanffy•20m ago•0 comments

Ask HN: Why doesn't Netflix add a “Theater Mode” that recreates the worst parts?

2•amichail•20m ago•0 comments

Show HN: Engineering Perception with Combinatorial Memetics

1•alan_sass•27m ago•2 comments

Show HN: Steam Daily – A Wordle-like daily puzzle game for Steam fans

https://steamdaily.xyz
1•itshellboy•28m ago•0 comments

The Anthropic Hive Mind

https://steve-yegge.medium.com/the-anthropic-hive-mind-d01f768f3d7b
1•spenvo•29m ago•0 comments

Just Started Using AmpCode

https://intelligenttools.co/blog/ampcode-multi-agent-production
1•BojanTomic•30m ago•0 comments

LLM as an Engineer vs. a Founder?

1•dm03514•31m ago•0 comments

Crosstalk inside cells helps pathogens evade drugs, study finds

https://phys.org/news/2026-01-crosstalk-cells-pathogens-evade-drugs.html
2•PaulHoule•32m ago•0 comments

Show HN: Design system generator (mood to CSS in <1 second)

https://huesly.app
1•egeuysall•32m ago•1 comments

Show HN: 26/02/26 – 5 songs in a day

https://playingwith.variousbits.net/saturday
1•dmje•33m ago•0 comments

Toroidal Logit Bias – Reduce LLM hallucinations 40% with no fine-tuning

https://github.com/Paraxiom/topological-coherence
1•slye514•35m ago•1 comments

Top AI models fail at >96% of tasks

https://www.zdnet.com/article/ai-failed-test-on-remote-freelance-jobs/
5•codexon•35m ago•2 comments

The Science of the Perfect Second (2023)

https://harpers.org/archive/2023/04/the-science-of-the-perfect-second/
1•NaOH•36m ago•0 comments

Bob Beck (OpenBSD) on why vi should stay vi (2006)

https://marc.info/?l=openbsd-misc&m=115820462402673&w=2
2•birdculture•40m ago•0 comments

Show HN: a glimpse into the future of eye tracking for multi-agent use

https://github.com/dchrty/glimpsh
1•dochrty•41m ago•0 comments