frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Show HN: Onesinglecounter, a Globally Available Counter

https://onesinglecounter.com
1•v3lmx•2h 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•1h ago
I just see a blank page?

Robotic tongue drummer bangs out all the ambient hits

https://blog.arduino.cc/2025/06/07/this-robotic-tongue-drummer-bangs-out-all-the-ambient-hits/
1•PaulHoule•2m ago•0 comments

China's New Army of Engineers

https://www.economist.com/china/2025/06/26/chinas-new-army-of-engineers
1•bookofjoe•4m ago•1 comments

Biocubes: A visual story of the living and the built

https://biocubes.net/
1•gmays•4m ago•0 comments

A practical guide to navigating compensation and promotion

https://blog.incrementalforgetting.tech/p/know-your-worth
1•mooreds•7m ago•0 comments

Generating Code and Content with AI

https://medium.com/cloud-security/artificial-intelligence-2e97415216c0
1•mooreds•8m ago•0 comments

A Beauty Cold and Austere (2017)

https://iplayif.com/?story=https%3A%2F%2Fgithub.com%2Fmzspivey%2FA-Beauty-Cold-and-Austere%2Fraw%2Fmaster%2FABCA5.gblorb
1•kqr•8m ago•0 comments

Lovely Tensors

https://xl0.github.io/lovely-tensors/
1•mooreds•12m ago•0 comments

The Plan to Re-Freeze the Arctic

https://thenarwhal.ca/real-ice-cambridge-bay-nunavut/
1•HR01•12m ago•0 comments

Show HN: Syft – Check if an Instagram page is legit before you pay

https://gosyft.com/demo
2•gavinships•17m ago•0 comments

Show HN: I'm an airline pilot – I built interactive graphs/globes of my flights

https://jameshard.ing/pilot
61•jamesharding•18m ago•8 comments

A Comprehensive List of Top AI Image Tools 2025

https://aiex.me/top-ai-image-tools
2•zack119•18m ago•0 comments

Android Workgroup for Swift

https://www.swift.org/android-workgroup/
2•subset•19m ago•0 comments

Future Pixel phones might not meet requirements for GrapheneOS

https://twitter.com/GrapheneOS/status/1933177989480456365
1•gasull•22m ago•0 comments

The Effect of Noise on Sleep

https://www.empirical.health/blog/effect-of-noise-on-sleep/
3•brandonb•22m ago•0 comments

Google is phasing out support for ClaimReview markup in Google Search.

https://developers.google.com/search/blog/2025/06/simplifying-search-results
1•shankysingh•22m ago•1 comments

Orange Me2eets:We made an end-to-end encrypted video calling app and it was easy

https://blog.cloudflare.com/orange-me2eets-we-made-an-end-to-end-encrypted-video-calling-app-and-it-was/
2•doomrobo•24m ago•0 comments

Career Counseling with Anastasia Gamick [video]

https://www.youtube.com/watch?v=uPBRezeyptM
2•surprisetalk•27m ago•0 comments

VMware perpetual license holder receives audit letter from Broadcom

https://arstechnica.com/information-technology/2025/06/vmware-perpetual-license-holder-receives-audit-letter-from-broadcom/
4•nobody9999•28m ago•0 comments

Web Numbers

https://ar.al/2025/06/25/web-numbers/
1•surprisetalk•30m ago•0 comments

Show HN: DevMatter – A simple form API for developers

https://devmatter.app
1•adityavinodh•31m ago•0 comments

UK Fintech Giant Revolut to Acquire BNP's Bank in Argentina

https://www.bloomberg.com/news/articles/2025-06-26/uk-fintech-giant-revolut-to-acquire-bnp-s-cetelem-in-argentina
3•wslh•31m ago•1 comments

Why Are Homes in Western US States So Expensive?

https://www.construction-physics.com/p/why-are-homes-in-western-states-so
9•surprisetalk•33m ago•1 comments

Hosting Website on Phone

https://rohanrd.xyz/posts/hosting-website-on-phone/~
1•quaintdev•34m ago•0 comments

The network is indeed trying to become the computer

https://www.theregister.com/2025/06/27/analysis_network_computing/
2•rntn•36m ago•0 comments

Fair(er) DRM GPU Scheduler

https://blogs.igalia.com/tursulin/fair-er-drm-gpu-scheduler/
1•mariuz•37m ago•0 comments

Financial Accounting

https://docs.tigerbeetle.com/coding/financial-accounting/
1•brson•39m ago•1 comments

Notes on AI and Writing

https://jasmi.news/p/32-notes-on-ai-and-writing
1•surprisetalk•43m ago•0 comments

Build and launch AI Assistants mobile apps

https://www.bravostudio.app/build-ai-assistant-app
1•petercod•44m ago•0 comments

New project to pioneer the principles of human genome synthesis

https://wellcome.org/news/new-project-pioneer-principles-human-genome-synthesis
2•sohkamyung•45m ago•0 comments

The Power and Beauty of Incrementalism

https://supernuclear.substack.com/p/the-power-and-beauty-of-incrementalism
2•surprisetalk•45m ago•0 comments