How to get started with Stanza

Getting started with Stanza using the FiberStanza example application.

Joseph Bironas

January 18, 2024

Getting Started with Stanza in Go

Now that our public Beta release is open, let's dive into our Go SDK repository. It contains a simple app harnessing the Fiber framework, that offers a solid starting point for understanding how to work with Stanza. This guide aims to be a clear and concise roadmap. It'll guide you through setting up the example application and navigating the Stanza UI. More importantly, you'll gain insight into how the Stanza SDK seamlessly integrates into your application, providing a robust mechanism to manage both inbound and outbound traffic. This is achieved through configuring objects and policies within the Stanza platform, ensuring your application remains operational under heavy loads and bad traffic patterns.

Prerequisites

Before diving in, make sure your account is setup and you’ve downloaded the SDK.

  • Create Your Stanza Account: Sign up at Stanza.
  • Clone the SDK Repository
git clone https://github.com/StanzaSystems/sdk-go

Navigating the Web Interface and Setting up a Guard

Find your API Key

Once you’ve created your account, it's time to get familiar with the Stanza UI:

  • Select Your Environment:
  • In the UI's upper right corner, find "Environments" and choose "dev". Stanza creates development and production environments by default, feel free to create more as needed.
  • Secure Your API Key:
  • Under "Administration" on the left navbar, hit the "Keys" tab.
  • Locate the "default key for dev" and unveil it using the eye-shaped visibility button.
  • Safeguard this key; you'll need it shortly.

Services and Guards

Creating a service and its corresponding guard is how Stanza starts to define application level traffic control policies:

  • Create a New Service:
  • Navigate to "Services" on the left navbar and click "+ Service".
  • In the "Create Service" form, enter "fiber-example" as the service name, choose "default" for the project, and activate "External".
  • Click “Save” and you'll be redirected to the service details page, revealing tabs for "Configuration", "Timeline", and "Guards".
  • Create a New Guard:
  • Under the "Guards" tab, opt for "+ Add Guard".
  • Craft your guard named "StressTest", align it with the "default" project, designate "Outbound" as the traffic type, and ensure "Report Only" is deactivated.
  • Click on "Save", you'll be directed back to the Service Details / Guards tab.

Fine-Tune Your Guard

Personalizing your guard is crucial for precise request management:

  • Access Your Guard's Settings:
  • On the left navbar, choose "Guards" and pick the "StressTest" guard you've just created.
  • In the "Configuration" tab, select "Edit" to modify the "Traffic Configuration".
  • Configure Traffic Limits:
  • Set "refillRate" and "burst" to values that let you visibly gauge the app's behavior (e.g., refillRate: 5, Burst: 6).
  • Activate the guard by ensuring "enabled" is set to "true".
  • Click on "Save".

Running the FiberStanza Example

With the Stanza control plane elements created, it's time to initialize and run the FiberStanza example:

  • Prepare Your Environment:
  • Navigate to the directory with the Stanza Go SDK.
  • Set environment variables for the Stanza API Key and Hub Address (replace `<your_api_key>` with the key you secured earlier):
export STANZA_API_KEY=<your_api_key>
export STANZA_HUB_ADDRESS=hub.stanzasys.co:9020
  • Initiate the Sample App:
  • Launch the app, which will resonate at localhost port 3000:
go run adapters/fiberstanza/example/server.go

 Testing the Application

To truly appreciate Stanza's prioritization and rate limiting capabilities, let’s load test the application:

  • Simulate Traffic:
  • Employ tools like Postman or vegeta to simulate user traffic.
  • For instance, with Vegeta, you can execute:
echo "aHR0cDovL2xvY2FsaG9zdDozMDAwL2hlYWx0aHo=" | vegeta attack -duration=20s -rate=20/s -header="X-User-Plan: free"
  • ...and similarly for the "enterprise" plan.
  • Observe and Analyze:
  • Monitor the difference in successful requests between the "free" and "enterprise" plans.
vegeta report free.gob | egrep "(Success|Status)"
  • Once the service hits the guard-configured threshold, the rate limiter will kick in and higher priority traffic will succeed at a greater rate.

Conclusion

Incorporating Stanza into your Go applications leads to higher quality user experiences and more reliable services. This walk through the setup, configuration, and testing of your Stanza integration has hopefully shown you how easy Stanza is to integrate with your Go applications. You can also work with TypeScript/JavaScript (Next/Express) and Python is coming soon. Now we’d like to hear from you. Your insights and feedback are invaluable, shaping our path forward. Please share your experiences, ideas, and achievements at support@stanza.systems

Joseph Bironas

Joseph is passionate about how engineering, leadership, and infrastructure combine to shape reliability efforts. He spent years at Google where he wound up leading multiple automation and tooling initiatives.

He's held a number of roles from building infrastructure and SRE programs, to product and data software efforts, to bringing cloud modernization and reliability best practices to cloud customers.

When he's not thinking about software, and its impact on people, he's probably playing guitar, tinkering with strings of LED lights, or growing hot chilies and making sauces out of them.