{ // Extract person data from the request body const { name, age, gender } = req.body; // Create a new person document using the Person model const person = new Person({ name, age, gender }); // Save the person to the database await person.save(); res.status(201).json({ message: 'Person saved successfully' }); } catch (error) { console.error('Error saving person:', error); res.status(500).json({ error: 'Error saving person' }); } });
cache, fallback to DB/upstream API. • Cache based on request parameters to avoid stale data. • Set proper cache TTL. • Watch cache hit ratio and fine tune expiry times accordingly. • Avoid caching user-specific or sensitive data.
- work with the DB driver • Have the ability to optimize your connection pool • Use caching when needed • Choose efficient - ◦ Serializer ◦ Log library ◦ Web framework