Skip to content
Notifications
Clear all

What's the best way to structure Snyk projects for a monolith vs microservices?

3 Posts
3 Users
0 Reactions
0 Views
(@billyj)
Reputable Member
Joined: 3 weeks ago
Posts: 249
Topic starter   [#23955]

Having recently undertaken a comprehensive migration from a monolithic application architecture to a microservices-based one, I was compelled to re-evaluate our entire Snyk implementation strategy. The organizational paradigms that served us well for the monolith became a significant source of friction and noise when applied to a dozen independent services. Through trial, error, and extensive benchmarking of different project structures, I've arrived at a set of principles that optimize for clarity, ownership, and actionable reporting in each architectural context.

For a **Monolithic Repository**, the primary challenge is avoiding a single, overwhelming Snyk project that obscures the context and priority of issues. My recommended approach is to structure Snyk projects by logical application layer or component *within* the monorepo, leveraging Snyk's path targeting.

* **Create separate Snyk projects** for the frontend (`./client/package.json`), backend API (`./server/package.json`), any auxiliary tools or scripts (`./tools/package.json`), and infrastructure-as-code definitions (`./terraform/**`).
* This segmentation allows for distinct vulnerability reporting, license policy enforcement, and dependency upgrade pull requests per component. It mirrors the internal ownership within your engineering teams, even if the code is physically co-located.
* Crucially, utilize Snyk Tags (e.g., `team:frontend`, `tier:production`, `service:checkout`) aggressively across all these projects. In a monolith, tags become your primary mechanism for creating unified views and reports across the entire codebase in the Snyk UI, enabling you to answer questions like "show all high/critical vulnerabilities for all production-tier components."

For a **Microservices Architecture**, the physical separation of codebases lends itself to a more 1:1 mapping, but introduces scale and consistency challenges.

* The foundational rule is **one Snyk project per service repository**. This seems obvious, but the nuance lies in how you manage them. A collection of 50+ individually imported projects is unmanageable.
* **Mandate the use of a uniform configuration file** (`snyk.yaml` or `/.snyk`) across all services. This ensures consistent severity thresholds, ignore rules, and license policies are applied, even if services are owned by different teams.
* **Implement a hierarchical tagging system** from day one. Every project should have tags for `team`, `service-name`, `environment`, and `data-classification`. This transforms your Snyk organization from a flat list of projects into a queryable observability platform for your security posture.
* **Leverage Snyk Organizations** to potentially segment by business unit or major product line if their policies differ fundamentally, though I generally advise using tags and projects within a single org for maximum cross-cutting visibility.
* For CI/CD, standardize on a shared pipeline template or GitHub Action that invokes Snyk testing, ensuring every service is scanned identically.

The pivotal difference in mindset is this: in a monolith, you use Snyk to *create* logical separation; in microservices, you use Snyk to *impose* logical unification. The monolith strategy is about breaking down a giant blob into actionable parts. The microservices strategy is about tying a hundred independent entities back together into a coherent, organization-wide security dashboard. Failure to adapt your Snyk project structure to your architecture will result in either a deluge of unactionable alerts or critical vulnerabilities being lost in the noise.

— Billy



   
Quote
(@emmap)
Estimable Member
Joined: 2 weeks ago
Posts: 98
 

Hi, I'm Emma. I'm a platform engineering lead at a mid-sized fintech (~300 engineers) where we run a mix of microservices and a couple of legacy monoliths, all monitored with Snyk. We've gone through this exact restructuring.

I agree with your starting point. My approach focuses less on component type and more on ownership and CI/CD. Here's what mattered most for us:

* **Ownership & Jira Mapping:** For microservices, each Git repo *must* be its own Snyk project. This lets you cleanly map `snyk-project -> service-owner-team -> their-Jira-project`. For a monolith, you can use path targeting, but you'll need to manually map those paths to team Jira projects in Snyk settings, which is a bit fiddly.
* **CI/CD Noise & Thresholds:** In a monolith, a single high-severity vulnerability in a shared lib can fail builds for *all* path-targeted projects simultaneously, creating alert spam. We set severity thresholds per Snyk project to manage this. With microservices, a bad update only affects that service's pipeline, isolating the blast radius.
* **License Policy Management:** Policies are global, but enforcement is per-project. For a monolith with multiple Snyk projects, you must apply the policy to each one individually. For microservices, you can apply policies in bulk by tagging projects with `service-type:api`, which saves a ton of admin time.
* **Reporting & Metrics:** Getting a per-team vulnerability count in a monolith means filtering by the manually-assigned `team` tag in reports. For microservices, it's automatic: one project = one team (usually). This made our security metrics for leadership way easier to build.

My pick is clear: if you have true, independently deployable microservices, you should have a 1:1 Snyk project to Git repo relationship. It mirrors your architecture and makes ownership unambiguous. For a monolith, path-based projects are your only real option, but spend the time upfront to tag them meticulously with owner and component type. What's your average team size and how many services are they typically responsible for? That can change how granular you get with the tagging.



   
ReplyQuote
(@ci_cd_crusader)
Reputable Member
Joined: 2 months ago
Posts: 235
 

Your point about path targeting for monoliths is solid, but it can get tricky with overlapping dependencies. If the backend and frontend both use the same vulnerable lodash version, you'll get duplicate high-severity alerts across two projects. We solved this by adding a separate "shared-library" Snyk project just for the `./shared-deps/package.json` directory, which cut down the duplicate noise significantly.

Also, remember to adjust your Snyk CI step to scan multiple paths. A single `snyk test --all-projects` on the repo root creates a messy project list. It's better to script separate `snyk test --file=./server/package.json` commands per logical component.


Commit early, deploy often, but always rollback-ready.


   
ReplyQuote