Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: A HN clone writen in Go (remoterenters.com)
115 points by andrewfromx on March 5, 2023 | hide | past | favorite | 65 comments
I've been trying to write my "go on rails" framework for years. I never quite got it like I wanted. There is gin and echo and all sorts of other frameworks and patterns but I finally found something I really like:

/foo/

/foo/bar/

/foo/bar/more/

That's it. Just three levels and all my controllers get passed in what's between the / with var names first, second, third.

In order to really make sure this framework could build something real I made a Hacker News clone. RemoteRenters.com is a HN just for articles about the remote work revolution since covid. Feel free to vote or submit to see how it all works!

Code is open source at: https://github.com/andrewarrow/feedback




Nice work. Here is some feedback:

1. Go has a major bottleneck and that’s the growth of its memory size when it’s under pressure. Templates bloat the memory quickly and make the site less performant at scale (aka if you put it on Heroku, you’d need more Dinos to support the traffic, which costs more.). Instead of GO templating, you can produce static pages and fill them up with JS Ajax or React, or whatever your front end flavor is and make that call a Go API you produce with the framework instead. This also helps you turn your site into an app if needed as well.

2. Saw somewhere you had database incremented user ids and other models? Not safe as it allows any bad actor to peruse your user base. Always do UUID as a scramble that can’t be iterated on.

Keep hammering. For everyone who says you don’t need a framework in Go, there are at least a few newbies who learn how to set up and run their Go server and stack from your framework.


> 1. Go has a major bottleneck and that’s the growth of its memory size when it’s under pressure. Templates bloat the memory quickly and make the site less performant at scale (aka if you put it on Heroku, you’d need more Dinos to support the traffic, which costs more.). Instead of GO templating, you can produce static pages and fill them up with JS Ajax or React, or whatever your front end flavor is and make that call a Go API you produce with the framework instead. This also helps you turn your site into an app if needed as well.

It will most likely be fast enough. If not there are libs that will compile your templates to Go code with very minimal overhead, or templating libraries that are much faster than builtin one.

I'd think adding megabytes of JS garbage just to run site would be opposite of "HN clone"


Amen to that. Half the reason I like this site is it loads instantly. Not showing spinning wheels just to display some text.

As for "working at scale", this post itself is id ~35 million. You could likely fit all of that into ram on a modestly sized server.


It's idiotic complaint really. I switched from Go templates to pre-compiled ones because of engineering wankery of personal project where I wanted to have page render take less than 1ms, and with templates it took like 3-4ms. Even with something complex at say 50ms per page you're looking at ~200req/sec/core which is a lot of traffic


I have to agree with you. I see this as a tendency for sites to start getting back to basics. Large frontend frameworks often cause more problems than they solve.


> Keep hammering. For everyone who says you don’t need a framework in Go, there are at least a few newbies who learn how to set up and run their Go server and stack from your framework.

This. A million times this. Please don't be discouraged by any negative responses you get here.


Does #2 actually apply if there's no private data being stored? If posts could be private/unlisted and I could just increment the id to find some, I'd agree with you.

Look at HN for example. Everything is public and they use incrementing ids for posts and comments.


And it's a bit of security through obscurity. There is a value to to that but for something that's not storing sensitive data then who cares.


2/ encrypt your ids before rendering them and decrypt them for queries. No need to store a huge string when int64 does the exact same.

Also, nothing wrong with incremental ids. Twitter and fb are doing just fine.


> Go has a major bottleneck and that’s the growth of its memory size when it’s under pressure. Templates bloat the memory quickly and make the site less performant at scale...

Do you have any references where one could read up on such issues and how to navigate them?


We’ve been using Go in production for 7 years, and benchmarking every architectural choice.


Anything more tangible you can share? By every indication I've come across, resource consumption of Go templates being problematic is an outdated notion.


> Go has a major bottleneck and that’s the growth of its memory size when it’s under pressure. Templates bloat the memory quickly and make the site less performant at scale

any resources or benchmark numbers to back this claim?


Not exposing user ids is a good thing. UUIDs may be a bad thing depending on needs. They cause poor locality in storage which can increase seek time.


1) You can also restart the server for 1s every month to achieve the same. Probably unnecessary because there's probably more than 12 features/fixes a year you'll want to push anyway.


Good job.

As an alternative view though, one of the nice things about Go, or specifically the http part of the stdlib, is that it composes well with libraries and middleware like Chi or Negroni. So rather than having to conform to an all-encompassing web framework, you can assemble just the tools you need for the problem at hand.


Someone once said, "It's good for simple projects but projects rarely stay simple." That's why I like frameworks and the batteries that they include.


Simple composable components are especially important for complex projects. The larger the project the less likely that the assumptions made by the framework will be a good fit for it.


But that's not important in the beginning and will likely lead to over engineering.


But that is why I dislike frameworks.

Whenever something is no longer simple, it is more work to customize them than it would have been to write something yourself, with judicious use of more specific libraries as opportunistically effective. That seems to present itself rather quickly every time I decide to test out a new framework.


What is an example of something simple vs complex?

I believe my services' APIs count as simple. HTTP verbs, url and query parameters, some auth headers and jwts, json payloads, and http error codes usually with a json body. As such, all my problems are easily solved with the chi package. I don't do much form handling as our UI handles that and uses our APIs. FWIW, our APIs handle billions of requests per day.

What is complex? I imagine things around templating, forms, and maybe (maybe!!) auth. Is that what drives framework advocates?

My past experience with a few were that they made simple things simple and hard things harder or impossible. I abandoned them about a decade ago however, so could be out of touch.


Sometimes you need batteries, not a nuclear plant bigger frameworks come from


Whenever I see code like the example routing, I have to wonder if a hash lookup would be more appropriate. This is especially when all the functions called are of exactly the same form, I immediately just want an interface for that and then define a map from “first” to handler.

The counter point in some languages (eg: Java) is that switch statements/expressions handle it this way under the hood at compile time depending on if it’s more efficient to use a map or a bunch of checks.

What is the actual best practice in go these days?


When routing is static, it's trivial and any solution will work. Like when your routes are all static /foo/bar and they merely use ?query params to pass info.

Not sure what you're asking, but handling dynamic segment routing ergonomically is where naive solutions tend to fail.

For example, a simple trie/map router needs additional logic to backtrack and try downstream routes. You wouldn't want `GET /users/42/show` to 404 in the following route table.

    /users/42/admin 
    /users/:id/show


Thanks for posting this will check it out.

It's very interesting that you've mentioned that you're trying to create "go on rails" and the fact that there are already similar other frameworks in go.

The author of Stanza language has this insightful article on the viability of a programming language for creating a powerful framwork like Ruby on Rails:

Stop Designing Languages. Write Libraries Instead:

http://lbstanza.org/purpose_of_programming_languages.html

It's very interesting because until today after more than 10 years of existence, not unlike Java, Go is still struggling to have a popular and robust framework ala Rails for its community.

Python has Zope and then Django to compete with Rails and I think they're the turning point for its rapidly increasing popularity about 20 years ago in the face of its potent programming language competitors at the time including Java, Ruby, TCL, Perl, C#, etc.


Because Go and other "modern" programming language don't want heavy framework like Rails, Spring, Django etc ...

It's not a struggle it's a choice. Light and composable libraries are the way to go not heavy framework.


Is there an advantage to limiting the route to three components? It feels limiting, and I'm not really sure what it buys you.


I mean, HN only has one and everything else is query params.



oh, yes, that code isn't even used anymore. Fix pushed.


Can’t read any comments - I have an ad blocker on, so I suspect it’s JS? Should be all static.


Awesome! Last week, I released "Launch your own HN-Clone" tool

https://www.hn.plus

I've tried to maintain true to most of the HN features and also included other features so you can grow your HN-clone community!



Very funny: https://remoterenters.com/stories/57cf0737-f8ed-6cf3-542d-2c...

I can't see the topic/title in the URL which makes clicking always risky.

I hope you have better rate limits than HN, where I would post something and can't reply to present my argument to others because I posted like 4 timed in an hour. That and I hope you have no shadowban features. May open and respectful discourse prosper.


Judging by minuses I get on my comments sometimes, there's no shadowban on HN. And I was never limited in trying to post reply.


Lucky me then. When you get enough downvotes, it kicks in and sticks for weeks


>"go on rails"

You should take a look at Crystal and Lucky.


I tried to google for both, do you have links?



ohh i see why my google search failed, I was adding the word "go" or "golang" because I thought these were GO rails frameworks.


I wonder what language and framework HN is using.



RSS would be a cherry on top :)


nice but font is a bit small.


I thought that was very fitting, just like with HN, I immediately zoomed in ;)


iPad's text size adjustment control works perfectly.


cringe


The real secret sauce to HN would be cloning dang.


Throw in some cloudflare, google, and AWS customer service responses while you are at it to make it realistic.


LLM-based dang clone? Hmm…


This exists and was featured on HN.

An LLM that generates text like a specific HN account, based on their prior comments.


Commenting on HN is a very small part of what dang does!


And patio11 &tc


Mega nitpick and completely off topic; it's just "&c". "Et" translates as "and" which can be replaced by the ampersand, "cetera" is "the rest".


My understanding is that "&" is actually a ligature of "Et". You can kind of see it if you squint your eyes!


yup this is correct


Yeah I realised after I made the comment. Thanks for the spot.


I’d love something like this just for python. Especially sans HN style moderation.


If there was a Django based HN clone in Python, I would be tempted to run an instance for topics I am interested in.


But who is going to visit your site? I dont mean to make a snarky comment, but I am curious as to how data is generated?


Worth to add in the title:

> An HN clone written in Go with Google's telemetry[0]

[0] https://news.ycombinator.com/item?id=34744948


No, a build time option that can be disabled is not relevant to the post

Do you pedantically point out that end users have to accept Oracle's end user license agreement to install the JRE when someone posts something written in Java, or that mp3s are patent encumbered when someone posts a music player? For crying out loud

Also, the FUD you linked to says the feature MAY be shipped. It hasn't even actually happened.

Go away.


Also, the current plan is that it would be opt-in. You'd have to explicitly enable it.


> Also, the FUD you linked to says the feature MAY be shipped.

Doesn't it worry you that they'd even consider this kind of stuff?

Also, a proposal by one of their developers is not FUD. Maybe suicide.


There is no Google telemetry in the site. Pattern matching on “Go” with whatever your recent issue is with it is a bad comment.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: