Not too long ago, we released a CLI update that makes building projects with multiple programming languages easier than ever. This enhancement streamlines the development of polyglot applications, allowing devs to use the best tools for each job without compromising efficiency or introducing complexity.
Why Polyglot Support Matters
In the real world, no single programming language can address every need optimally. You might prefer Python for AI or data science tasks due to its rich ecosystem of libraries, while choosing a language like Go for its high performance in backend services. Polyglot support bridges the gap, enabling you to mix and match languages to build robust, efficient, and maintainable systems.
How Does It Work?
Nitric's basedir property for services allows you to define separate build contexts for different parts of your application. This means you can use independent dependency management systems for each service without worrying about conflicts. Here's an example configuration:
name: pygoservices:- basedir: pythonmatch: services/*.pyruntime: pythonstart: uv run watchmedo auto-restart -p *.py --no-restart-on-command-exit -R uv run $SERVICE_PATH- basedir: gomatch: services/*runtime: gostart: go run ./$SERVICE_PATH/...runtimes:python:dockerfile: ./runtimes/python.dockerfilego:dockerfile: ./runtimes/golang.dockerfile
This configuration ensures that your Python and Go services remain cleanly separated, each using its own runtime and dependencies.
Sharing Cloud Resources Across Languages
To enable seamless integraton between services written in different languages, Nitric uses simple names to allow cloud resources to be shared. Here’s an example of how a Go service can publish messages to a Python service using a shared topic called hello
:
package mainimport ("context""fmt""github.com/nitrictech/go-sdk/nitric""github.com/nitrictech/go-sdk/nitric/apis""github.com/nitrictech/go-sdk/nitric/topics")func main() {api := nitric.NewApi("main")topic := nitric.NewTopic("hello").Allow(topics.TopicPublish)api.Get("/go/hello/:name", func(ctx *apis.Ctx) {name := ctx.Request.PathParams()["name"]// Send a message to the Python servicetopic.Publish(context.TODO(), map[string]interface{}{"name": name,})ctx.Response.Body = []byte(fmt.Sprintf("Hello %s", name))})nitric.Run()}
from nitric.resources import api, topicfrom nitric.application import Nitricfrom nitric.context import MessageContexthelloTopic = topic("hello")@helloTopic.subscribe()async def hello_world(ctx: MessageContext):print(f"Received a message from the Go service: {ctx.req.data}")Nitric.run()
In this setup, the Go service sends messages to the hello topic, which the Python service subscribes to and processes. This design allows you to harness Python's rich library ecosystem for tasks like machine learning while leveraging Go's performance for backend logic. Embrace the Best of Both Worlds
Polyglot development lets you avoid settling for incomplete or underperforming ports of your favorite libraries. With Nitric's multi-language support, you can tap into the full potential of each programming language, creating a stack that's optimized for your needs.
Why choose between power and flexibility when you can have both? Nitric makes polyglot microservices simple, effective, and ready for the cloud.
Checkout the latest posts
Hey ops people, you’re doing it wrong. (But we can fix it!)
Challenging operations teams on a commonly made mistake
Cloud SDKs Can Chain You Down
With the right level of abstraction over cloud resources, we can separate the responsibilities and concerns of developers and operations teams.
Nitric adds Deno 2 support
Building applications with Deno 2 and Nitric
Get the most out of Nitric
Ship your first app faster with Next-gen infrastructure automation