r/javahelp • u/RuairiSpain • Apr 15 '21
Codeless Need advice: Java Software Architecture for SaaS startup doing CRUD and REST APIs?
First post!
I'm helping out a SaaS startup on the technology stack and software architecture. I'm a Node and .Net software architect, with only bits of Java knowledge. Our developer team want to use Java because that's their preferred platform.
I'm not up-to-date with software architecture choices for Java. My first plan is to start with a modular monolith than we can split out into microservices as the startup grows. We'll use Postgres and Redis for data and caching. I'm not familiar with Java specific solutions for messaging, JPA or REST frameworks.
The business is a Accountancy system for restaurants, so it's a fairly straightforward LOB business with CRUD and bits of integration to 3rd party REST API. In a previous company we use JHipster to generate the backend scaffolding from a annotated data model, and it worked well for that company.
My question: Is JHipster still a valid choice for a startup that will want to grow eventually to use docker containers? (Short term plan is to not use K8s, until we need that complexity).
Are their other Java frameworks that I should research for fast iteration of the backend?
Any recommendations appreciated, cheers 🍻
6
u/GuyWithLag Apr 15 '21
For a startup starting with a monolith is absolutely the right thing to do. If you're slightly careful with your internals, you can even do 0-downtime upgrades and red-green deployments.
May I recommend Quarkus as the application framework? It has a lot of velocity and uses a lot of existing standards, plus a wide array of integrations. One negative is that a full native build takes some minutes, but that makes sense to run on a full CI/CD build / release.
One thing that I'd like to point out is to build an integration testing scaffold for the system that can be run on the developers platform via a plain `mvn clean verify`; this allows you to enforce rich tests on the external side of the application, while leaving the internals to evolve fast.
Additionally, if you do the above simply starting up a local instance that connects to a staging environment is a small step away and a true godsend.
1
u/RuairiSpain Apr 15 '21
Thank you, will research Quarkus and your suggestions.
Cheers!
5
u/edubkn Apr 15 '21
Quarkus is a terrible choice for a non experienced java developer. You're going to spend more time fighting it than writing business code.
1
u/GuyWithLag Apr 16 '21
If they're doing a SaaS startup with no senior engineers that can provide a green path for juniors, they're fucked both ways and sideways anyways.
You will have issues with any framework, no matter what; I've gone through enough Spring internals that Dropwizard was a breeze, but that still had it's fair share of issues.
1
u/Kyy7 Apr 16 '21
Quarkus is still pretty new when it comes to Java and hence probably not as tried and true as many of the alternatives. It does however seem like something a startup could use to offer something faster and leaner to their clients.
14
u/errandum Apr 15 '21
People are giving you alternatives to the Spring Framework.
Don't. Not that there aren't many alternatives that perform better, but if you are a startup, you don't want to spend your dev doing devops.
It seems that you are doing a CRUD app, so Spring is more than enough. Time to market is more important than min-max. You can always scale later if you need to with spring, just make sure your app is mostly stateless on the applicational side so it can scale horizontally out of the box.
Finally, if you foresee any chance of scaling beyond reasonable limits, I'd recommend setting your data layer on something like Cassandra or Couchbase if you don't mind NoSQL. They are built to scale and distribute out of the box. They will shard themselves with almost no setup at all (adding and removing nodes is extremely easy).
Or, if you are not comfortable, just do the mysql or postgresql since they are most likely enough for most crud applications (unless you facebook yourself overnight)
But whatever you do, go for comfort. Don't worry if it's not the best possible solution, just go for turnover instead of maximum efficiency.
5
u/Bodine12 Apr 16 '21
I second this. Spring is great for straightforward apps like what you’re building and will easily (some would argue it’s misleadingly easy) integrate crud/REST.
-3
u/captainMaluco Apr 16 '21
Disagree, Spring is a terrible framework for microservice applications. If you're building an application that you foresee eventually being complex enough to warrant a microservice architecture, Spring is a terrible choice. If you are on the other hand building a online store that can probably stay a monolith forever, Spring is all you need. Doesn't sound like OP is doing that though, so I'd strongly discourage use of Spring in this situation, but OP will have to judge for himself.
Also your advice about databases is incorrect, it's absolutely possible to scale postgres to very large scales indeed. If you don't want the hassle of scaling your data layer, the best thing to do is to use a hosted database. If you for example use AWS for your application hosting, you can look into Aurora or DynamoDb. Other hosting services provide other similar alternatives.
1
u/errandum Apr 16 '21
Ok, I was going to ignore you since people saying "terrible" without any arguments usually are not doing it in good faith, but I'll answer with actual data:
I actually work in a company that require strict SLAs to be met and it's one of the biggest multi-media conglomerates in the world (literally).
We have Spring Boot microservices that handle anything from payments to video and metadata distribution that are horizontally scaled with kubernetes to handle anything from 5 to 5000 requests per second depending on the service. We also have dropwizard, vert.x, node.js and many more.
My point is, any modern framework can handle whatever you throw at it. I can tell you that for batch processing vert.x is crazy good with non-blocking I/O. But we also have some batch processing services in spring that are reactive. And others that aren't and we use coroutines to parallelize everything. They all meet their NFRs
You can make anything work if you know what you're doing.
Now the data layer... And here you are plain wrong.
We use Aurora, by the way. If you need ACID, it's a very good choice (but expensive). But it follows a Master -> Slave configuration where you can only write to the master (you will read from the slaves, most of the time). Since you can only write to the master, if you get too big (we did) you can saturate your master. You can get slow. You can send the master down (and credit to them, they recover gracefully to one slave that is promoted, Aurora is really good!).
But Master->Slave means that every replica needs to know everything. You can do sharding with mysql if you know what you are doing, but not out of the box and not easily. The Aurora approach is very good for consistency and good enough for performance. I'd recommend it for anything that requires ACID. Even with multi-region, but that is not as magic (regional failover requires intervention)
But then you have both Couchbase and Cassandra.
Couchbase has buckets (1024 I think) and each server will handle X amount of buckets (usually chosen by your key). If you add another server to your cluster? Buckets get rebalanced automatically and nothing goes down and everything is then automatically redistributed. You can scale to infinity (or well, 1024 I guess) and you can even have transactions if you really want to, and since the key decides where it runs, the transaction is always run in a replica and consistency maintained in a relatively performant way ( (from my understanding, we don't use transactions since we design things to be performant without them).
But you are writing to all your instances and reading from all your instances. The load distribution is automatic and the read/writes are using optimistic locking by default, so you can even recover from concurrency issues.
Cassandra is very similar with the sharding based on the inner key (I think), but I've never scaled it, only used the cluster, so I can't tell you how it's done. Just that it is crazy good in terms of performance, as long as you don't need transactions.
Honestly, I don't know why you have to be so contrarian. I can agree that many solutions are good and in the modern world of IT, everything is good enough.
But there are so many resources out there for Spring with configurations and examples for pretty much any example. With spring boot you can add only the dependencies you need (eg: only rest and data and ignore the rest), so the "monolith" myth is long gone by now.
1
u/captainMaluco Apr 18 '21 edited Apr 18 '21
I'm not saying it's not doable, I've done it myself many times, I just wouldn't recommend it based on my experiences. The stack you describe sounds oddly familiar actually, do you work for Discovery Networks? Their "Sonic" platform is built on vert.x and Spring(can't be that common a combination, right?), and it does work, it's just not what I would use if I were to build a similar platform from scratch today.
I'd probably use Micronaut actually, for its simplicity, vastly superior performance(equates to cheaper hosting, since you need less of it), and lastly cause I just like their design philosophy better.
For the databases, I wouldn't expect a new startup to run into the same scaling issues a giant like Discovery does, and for some types of data, SQL is simply the best choice. Nothing wrong with nosql, but don't pick it for the wrong reasons. If your data model fits a nosql model, then great, go wild with it. I've had great experiences with DynamoDb in particular, but Cassandra, elastic, couch and mongo are all good choices too. It all depends on the particular need you have, and general assessments are impossible to make correctly.
Many huge companies build microservices with Spring, but I think they're making a mistake.
Actually it's kinda funny that you'd bring up Discovery as an argument for Spring performance, given that all performance sensitive applications there run on vert.x.
Oh I should add, I've run Micronaut services serving up 25k req/s without breaking a sweat. 5k is peanuts 😉
1
u/errandum Apr 18 '21
1- Not discovery. Think bigger.
2- Those are the numbers of the services I'm directly involved with. We have services (eg: identity services) that peak at higher numbers, but I don't manage them and don't know their exact stack, so I can't speak about them.
Never said there aren't things that perform better than Spring, I actually said the opposite. I completely agree that some things are better. Also, I just told you we have services that are blazing fast and are not on spring. 5k requests per second is anything but rookie numbers and more than enough proof that Spring can be scaled...
But I'll repeat what I said:
1- It is easier to set up due to a multitude of resources and recipes already available everyone on the internet, for free!
2- The cost is negligible until you're scaling them to the dozens of pods. And even these are debatable. Tomcat consumes more resources than jetty, which you can use with one line in the config file. Which in turn, consumes more resources than netty, if you know what you're doing and supporting a reactive stack. You can tune your spring and make the difference almost negligible...
3- Picking comfort is way more important than min max, in my experience. And it is also way way way wayyyy easier to hire someone that knows Spring than Micronaut, at least where I'm from.
4- Time to market is usually more important than anything else, and comfort is paramount to do so.
About the NoSQL, you bet I'll recommend it now. I've been through the pains of scaling an SQL service that should not have been one. Migrating from SQL to anything not relational is a pain, since relational models don't usually fit a non relational one without data duplication everywhere.
So I recommend it now so they can model with a NoSQL paradigm in mind. Nowadays the support for most of them in spring is transparent to the devs, since you use your repositories anyways. You win almost nothing by going with the mysql/postgresql route, even if they are actually performant nowadays. But if you ever need scaling in your database, the first thing you turn off is the consistency, so you end giving up on the biggest upside (in my opinion) of a relational database.
Actually it's kinda funny that you'd bring up Discovery as an argument for Spring performance, given that all performance sensitive applications there run on vert.x.
You brought discovery, I brought vert.x because I know performance (or at least I think I do), but for a simple CRUD application Spring Boot is enough. More than enough.
6
Apr 16 '21
As a Java developer, I use Spring Boot. It is built on top of Spring to reduce builder plate code to reduce your time to market and it has modules for everything from security to REST and everything in between.
4
u/Kyy7 Apr 15 '21
Are their other Java frameworks that I should research for fast iteration of the backend?
Seems that JHipster uses spring-framework so maybe alternatives would be to use Apache Karaf and OSGi Framework or JavaEE with one of the many available application servers.
Apache Karaf with OSGi works pretty nice using annotation based dependency injection with the declarative services, removing the need to mess with those hopefully archaic XML blueprints. Too bad it's not as trendy as spring and the developers so many of the tutorials can be a bit dated and hard to find. Karaf also supports many other frameworks and programming models as well and there's even Red Hat supported version (Fuse) if that's something you might fancy.
JavaEE and Application servers like Glassfish, Payara etc are still something I am researching myself so don't know much about them.
1
u/ChrisLeeBare Apr 16 '21
I second jHipster. We are using this also and it’s super easy to generate a basic crud app. And if you know spring-Boot you can extend the app easily. Deployment to cloud foundry, heroku or kubernetes is also sleek and easy.
3
u/y-am-i-ear Apr 15 '21
Doesn’t jhipster also support Docker?
1
u/Kyy7 Apr 15 '21
Most things do and it can even make sense to run multiple modules on a container to share and save resources.
1
u/baconialis Apr 16 '21
You won't go wrong with Spring.
JHipster is a cool project I take want to be used now widely! In terms of productivity it'll give you a lot for free.
0
u/captainMaluco Apr 16 '21
If you foresee this turning into a microservice architecture you should probably look into Micronaut. It boasts much better performance and quicker startup times than Spring (which most people seem to recommend for reasons i do not understand)
Startup time will be particularly important if you plan to host in kubernetes where instances are ephemeral.
Developing in Micronaut is also a joy, and if you're comfortable with using Rx.Java you can squeeze some serious performance out of it.
Source: I've used it to serve around 25k req/s on a platform with 250 million monthly active users. P99 response times sub 20ms.
•
u/AutoModerator Apr 15 '21
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.