Skip to main content
Post Closed as "Needs more focus" by gnat, DavidT, Doc Brown
Nonsense in title fixed
Link
Doc Brown
  • 214k
  • 34
  • 394
  • 603

How to you properly choose between two equivalent implementations?, and how do youto prove you picked the correct one?

Source Link

How to you properly choose between two equivalent implementations? and how do you prove you picked the one?

Thinking about non functional requirements (the -ities) and other concerns, which approach would you choose and why? consider the two snippets

Direct Supabase Connection

import { useState, useEffect } from "react"
import { createClient } from "@supabase/supabase-js"

export function GeneralTab() {
   const [topicList, setTopicList] = useState([])

   const fetchTopics = async () => {
      try {
         const supabase = createClient(process.env.SUPAURL,process.env.SUPAPUBLIC)
         const { data } = await supabase.from("topics").select('topic')
         setTopicList(data.map(item => item.topic))
      } catch (error) {
         console.error("Error fetching topics:", error)
      }
   }
   useEffect(() => {fetchTopics()}, [])
}

Microservice Connection

import { useState, useEffect } from "react"

export function GeneralTab() {
   const [topicList, setTopicList] = useState([])

   const fetchTopics = async () => {
      try {
         const response = await fetch("https://your-microservice-endpoint.com/topics")
         const data = await response.json()
         setTopicList(data.map(item => item.topic))
      } catch (error) {
         console.error("Error fetching topics:", error)
      }
   }
   useEffect(() => {fetchTopics()}, [])
}

Direct Supabase Connection

is simpler, faster to develop, and potentially has lower latency, but it exposes the API key and is less flexible.

Microservice Connection

offers better security, scalability, and flexibility but adds complexity and potential latency.