Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

How can a Java developer run an open-weight LLM locally for development, for example with Ollama, and call it from Spring Boot? What limits should they expect compared with a hosted model?

Ollama downloads quantized open-weight models and serves them through a local HTTP API on port 11434, and Spring AI and LangChain4j both have Ollama integrations configured with a base URL and a model name. Quantization to 4 or 8 bits shrinks the memory needed so models fit on a laptop, with some quality loss. Local models are usually smaller and weaker than hosted frontier models, slower without a GPU and shorter in practical context, but no data leaves the machine, there is no per-token cost and they work offline, which makes them good for development and tests as long as the production model is evaluated separately.

Why this question is asked

Calling a hosted model from day one of development means API keys on every laptop, costs for every test run, and company data sent to an outside provider while we are just experimenting. A local model removes all three. Interviewers ask this to see whether a developer can set up that loop and, just as important, whether they understand what a local model can and cannot tell them about production. In this answer, we will set up Ollama, call it from Spring Boot, understand quantization and memory, compare local and hosted models, and decide where local models fit in the workflow.

1A Quick Recap: Open-Weight Models and Runtimes

An open-weight model is one whose trained weights are published for download, such as models from the Llama, Mistral, Qwen or Gemma families, under licences that vary in what they allow. The weights alone are just large files; to use them we need an inference runtime that loads them into memory and runs generation.

Ollama is one such runtime, popular for local development. It downloads models from its library in a ready-to-run quantized format, manages them on disk, runs them on the CPU or a GPU if one is available, and exposes a local HTTP API. Similar tools exist, such as llama.cpp's server or LM Studio, but Ollama has first-class integrations in both Spring AI and LangChain4j.

2Running a Model With Ollama

After installing Ollama, we pull a model and can try it from the command line. The server listens on localhost port 11434 by default.

Shell
$ ollama pull llama3.2 # downloads a ~2 GB quantized 3B-parameter model
$ ollama run llama3.2 "Say hello in one word"
Hello!
$ curl http://localhost:11434/api/chat -d '{"model": "llama3.2", "stream": false,
"messages": [{"role": "user", "content": "2 + 2 = ?"}]}'
{"model":"llama3.2","message":{"role":"assistant","content":"4"},"done":true, ...}

Model names and sizes in Ollama's library change over time, so we check the library for the current tags; the pattern stays the same.

3Calling It From Spring Boot

With Spring AI, we add the Ollama starter and set the base URL and model. Because our code uses ChatClient, the same service can run against Ollama on a laptop and against a hosted provider in production by switching configuration profiles. Starter artifact and property names have changed across Spring AI releases, so check your version's reference documentation.

XML
<!-- pom.xml, version managed by the Spring AI BOM -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-ollama</artifactId>
</dependency>
# application-local.properties
spring.ai.ollama.base-url=http://localhost:11434
spring.ai.ollama.chat.options.model=llama3.2
spring.ai.ollama.chat.options.temperature=0.2
// Service code, identical for local and hosted models
@RestController
class HelloController {
private final ChatClient chat;
HelloController(ChatClient.Builder builder) { this.chat = builder.build(); }
@GetMapping("/ask")
String ask(@RequestParam String q) {
return chat.prompt().user(q).call().content(); // /ask?q=2%2B2 -> "4"
}
}

LangChain4j works the same way with its OllamaChatModel builder, where we pass the base URL and model name. In both cases the code that calls the model does not know or care that the model is local.

4Quantization: How a Model Fits on a Laptop

A model's size in memory is roughly its number of parameters times the bytes per parameter. Trained weights are usually stored as 16-bit numbers, two bytes each, so an 8-billion-parameter model needs about 16 GB just for the weights, more than most laptops can spare. Quantization stores each weight with fewer bits, typically 8 or 4, using clever rounding schemes that keep most of the information. At 4 bits, the same 8B model needs around 5 GB.

There is a cost: each weight is less precise, so the model's quality drops somewhat, usually a little at 8 bits and more noticeably at 4 bits, especially for reasoning and exact facts. Memory also has to hold the KV cache for the context, so a longer context needs more memory on top of the weights.

Approximate memory for weights (excluding context)
Model size16-bit8-bit4-bit
3B parameters~6 GB~3.5 GB~2 GB
8B parameters~16 GB~9 GB~5 GB
70B parameters~140 GB~75 GB~40 GB
Rough figures; real files vary by format. A 16 GB laptop runs 3B to 8B models comfortably at 4 bits.

5What to Expect Compared With a Hosted Model

A model that fits on a laptop is usually much smaller than a hosted frontier model, often by an order of magnitude or more in parameters, so it is weaker at complex reasoning, long documents, following detailed instructions and rare facts. Without a GPU, generation is slow, perhaps 5 to 20 tokens per second on a laptop CPU for a small model, compared with fast hosted APIs. And while some models advertise long context windows, running them locally with long contexts needs a lot of memory, so in practice we work with a few thousand tokens; Ollama also uses a modest default context length that we may need to raise in the options.

The benefits are real too. No data leaves the machine, which makes it safe to experiment with internal documents. There is no per-token cost, so we can run tests as often as we like. And it works offline, on a train or in a locked-down network.

6Where Local Models Fit

So local models are ideal for development and for automated tests of our plumbing: does the service build the prompt correctly, parse the structured output, stream the response, handle timeouts and errors? They are also a reasonable choice for some simple production tasks when data must stay on premises, if evaluation shows the quality is good enough.

What they cannot do is tell us how the production model will behave. A prompt that works on a 3B local model may work better or differently on the hosted model, and the reverse. So we keep a separate evaluation of the production model on a real evaluation set, and never treat a passing local test as proof of production quality.

7Follow-up questions

How do we use a GPU with Ollama?

Ollama uses a supported GPU automatically when it finds one, including Apple Silicon's integrated GPU on Macs, which is why Macs with plenty of unified memory run local models well. On Linux machines with NVIDIA GPUs, the right drivers are needed; when a model does not fit in GPU memory, part of it runs on the CPU and generation slows down.

Can we run Ollama in Docker for the team?

Yes, there is an official ollama/ollama image, and for tests Testcontainers has an Ollama module. Models are large, so we mount a volume or cache the image with the model pulled in, to avoid downloading gigabytes on every run.

Are open-weight models free to use commercially?

It depends on the licence. Some use permissive licences such as Apache 2.0, while others have their own terms with conditions on use or company size. We check the specific model's licence before any production use.

8Conclusion

In this answer, we saw how to run an open-weight model locally with Ollama, which serves quantized models on a local HTTP API, and call it from Spring Boot through Spring AI's Ollama starter or LangChain4j by setting a base URL and model name. Quantization to 4 or 8 bits lets models fit on laptops with some quality loss. Local models are smaller, weaker, slower without a GPU and limited in practical context, but they keep data on the machine, cost nothing per token and work offline, so they are great for development and tests while the production model is evaluated separately.

What to say in the interviewAbout 90 seconds aloud

Open with

For local development I would install Ollama, which downloads open-weight models in a quantized format and serves them on a local HTTP API at port 11434, then pull a small model with ollama pull.

Then, if they want more

In Spring Boot I add the Spring AI Ollama starter and set the base URL and the model name in a local profile; because the code uses ChatClient, the same service runs against a hosted provider in production by switching configuration. LangChain4j has an equivalent OllamaChatModel.

Quantization is what makes this possible on a laptop: storing weights in 4 or 8 bits instead of 16 cuts an 8-billion-parameter model from about 16 GB to about 5 GB, at some cost in quality.

I would expect a local model to be smaller and weaker than a frontier hosted model, especially at reasoning and long instructions, slower without a GPU, maybe 5 to 20 tokens per second on a CPU, and limited in practical context by memory.

The benefits are that no data leaves my machine, there is no per-token cost and it works offline, so it is excellent for development and for tests of the plumbing, such as prompt building, parsing, streaming and error handling. But it does not predict production quality, so I evaluate the production model separately on a real evaluation set.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring AI reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How can a Java developer run an open-weight LLM locally for development, for example...": https://scrivio-interview-library.netlify.app/spring-boot/llm-fundamentals/564701f571/